Created
January 19, 2018 17:21
-
-
Save xealgo/ebb7e8678358fb6977400653d9f4c037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/rdb/user.go | |
// User satisfies user store interface | |
type User struct { | |
db *rdb.DB | |
} | |
func New(db *rdb.DB) User { | |
return &User{db: db} | |
} | |
func (u *User) Get(..) { | |
... | |
} | |
func (u *User) Save(..) { | |
... | |
} | |
func (u *User) Remove(..) { | |
... | |
} | |
// api/users.go | |
type Users struct { | |
userStore users.Store | |
... | |
} | |
func New(store users.Store, ...) Users { | |
return &Users{userStore: store} | |
} | |
func (u *Users) SomeHandler(ctx context.Context) { | |
user, err := u.userStore.Get(1) | |
... | |
} | |
// maybe go further also...(I haven't done this yet) | |
// users/users.go | |
type User struct { | |
store Store | |
Name string | |
... | |
} | |
func (u *User) Get(id uint64) { | |
store.Get(id, &u) | |
... | |
} | |
// main.go | |
func main() { | |
db := rdb.New(...) | |
us := rdb.New(db) | |
uc := api.New(us) | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment