Skip to content

Instantly share code, notes, and snippets.

@chris001177
Created June 21, 2019 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris001177/6a08b3c03d73ed9265aedbe8edc54a84 to your computer and use it in GitHub Desktop.
Save chris001177/6a08b3c03d73ed9265aedbe8edc54a84 to your computer and use it in GitHub Desktop.
package main
// We use interfaces as the types of our database instances
// to make it possible to write tests and use mock implementations.
type userDB interface {
userRoleByID(id string) string
}
// Note the naming `someConfigDB`. In actual cases we use
// some DB implementation and name our structs accordingly.
// For example, if we use MongoDB, we name our concrete
// struct `mongoConfigDB`. If used in test cases,
// a `mockConfigDB` can be declared, too.
type someUserDB struct {}
func (db *someUserDB) userRoleByID(id string) string {
// Omitting the implementation details for clarity...
}
type configDB interface {
allPermissions() map[string][]string // maps from role to its permissions
}
type someConfigDB struct {}
func (db *someConfigDB) allPermissions() map[string][]string {
// implementation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment