abstraction
This commit is contained in:
21
api/db.go
Normal file
21
api/db.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package api
|
||||
|
||||
import "errors"
|
||||
|
||||
func dbGetUser(id int64) (*User, error) {
|
||||
for _, u := range users {
|
||||
if u.ID == id {
|
||||
return u, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("User not found")
|
||||
}
|
||||
|
||||
func dbGetMessage(id string) (*Message, error) {
|
||||
for _, a := range messages {
|
||||
if a.ID == id {
|
||||
return a, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("Message not found")
|
||||
}
|
Reference in New Issue
Block a user