Skip to content

Instantly share code, notes, and snippets.

@ericelsken
Last active July 17, 2018 23:03
Show Gist options
  • Save ericelsken/b942b31c8916ce6b35a7b300e92162e8 to your computer and use it in GitHub Desktop.
Save ericelsken/b942b31c8916ce6b35a7b300e92162e8 to your computer and use it in GitHub Desktop.
User QueryRepo and Repo types. From https://github.com/AgencyPMG/go-from-scratch
//QueryRepo provides methods for retrieving Users.
type QueryRepo interface {
//Get should return the User whose Id equals id.
//
//An error should be returned if the User does not exist or there was an error
//attempting to load the User.
Get(ctx context.Context, id data.Id) (*User, error)
//GetEmail should return the User whose Email equals email.
//
//An error should be returned if the User does not exist or there was an error
//attempting to load the User.
GetEmail(ctx context.Context, email string) (*User, error)
//List should return all Users in the application.
//They should be sorted by their lexicographic Email order.
List(ctx context.Context) ([]*User, error)
}
//Repo provides method for creating and updating Users
//as well as promotes the QueryRepo interface.
type Repo interface {
//QueryRepo is promoted here to indicate a Repo contains all query methods.
QueryRepo
//Add should add u to the underlying storage repository.
Add(ctx context.Context, u User) error
//Set should update all stored fields of u in the underlying storage repository.
//The update should use u.Id for determining which entity to update.
Set(ctx context.Context, u User) error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment