Documentation ¶
Index ¶
- Constants
- Variables
- type Bout
- type BoutDB
- type BoutService
- type Category
- type Event
- type EventDB
- type EventService
- type Fencer
- type FencerDB
- type FencerService
- type Item
- type Match
- type MatchDB
- type MatchService
- type Pair
- type PairList
- type Plurality
- type PriorityQueue
- type School
- type SchoolDB
- type SchoolService
- type Seeding
- type SeedingService
- type Services
- type ServicesConfig
- func WithBout() ServicesConfig
- func WithEvent(seasonStartDate time.Time) ServicesConfig
- func WithFencer() ServicesConfig
- func WithGorm(dialect, connectionInfo string) ServicesConfig
- func WithLogMode(mode bool) ServicesConfig
- func WithMatch() ServicesConfig
- func WithSchool() ServicesConfig
- func WithSeeding(minBouts int) ServicesConfig
- func WithSquad() ServicesConfig
- func WithUser(pepper, hmacKey string) ServicesConfig
- type Squad
- type SquadDB
- type SquadService
- type User
- type UserDB
- type UserService
Constants ¶
const ( // ErrNotFound is returned when a resource cannot be found in the database. ErrNotFound modelError = "models: resource not found" // ErrLoginInvalid is returned when an attempt to authenticate a user fails. ErrLoginInvalid modelError = "models: incorrect email address or password" // ErrEmailRequired is returned when an email address is not provided when creating a user. ErrEmailRequired modelError = "models: email address is required" // ErrEmailInvalid is returned when an email provided does not match our requirements. ErrEmailInvalid modelError = "models: email address is invalid" // ErrEmailTaken is returned when an email provided is already in use or is otherwise unavailable. ErrEmailTaken modelError = "models: email address is unavailable" // ErrPasswordRequired is returned when a create is attempted without a user password provided. ErrPasswordRequired modelError = "models: password is required" // ErrIDInvalid is returned when an invalid ID is provided to a method like Delete. ErrIDInvalid privateError = "models: ID provided is invalid" // ErrRememberRequired is returned when a create or update is attempted without a set user remember token hash. ErrRememberRequired privateError = "models: remember token is required" // ErrNameRequired is returned when a create is attempted on a resource without a name provided. ErrNameRequired modelError = "models: name is required" // ErrInUse is returned when a delete is attempted on a resource in use. ErrInUse modelError = "models: resource is in use and cannot be deleted; please free the resource and try again" // ErrCategoryInvalid is returned when an invalid (gender-weapon) category is used. ErrCategoryInvalid modelError = "models: category is invalid" // ErrScoreLeftInvalid is returned when a bout score is not between 0 and 5 (inclusive). ErrScoreLeftInvalid modelError = "models: left score must be between 0 and 5, inclusive" // ErrScoreRightInvalid is returned when a bout score is not between 0 and 5 (inclusive). ErrScoreRightInvalid modelError = "models: right score must be between 0 and 5, inclusive" // ErrScoresEqual is returned when the scores of two fencers in a bout are equal. ErrScoresEqual modelError = "models: scores in a bout must be different" // ErrFencerLeftInvalid is returned when provided fencer on the left does not exist in the database. ErrFencerLeftInvalid modelError = "models: fencer on the left does not exist in the database" // ErrFencerRightInvalid is returned when provided fencer on the right does not exist in the database. ErrFencerRightInvalid modelError = "models: fencer on the right does not exist in the database" // ErrFencersNotUnique is returned when the fencers of a bout are the same. ErrFencersNotUnique modelError = "models: fencers on left and right cannot be the same" // ErrFencerIsBye is returned when a fencer with a non-false value for Bye is Created or Updated. ErrFencerIsBye modelError = "models: real fencers must have Bye=true. Please contact an administrator if you see this error" // ErrSchoolInvalid is returned when the provided school does not exist in the database. ErrSchoolInvalid modelError = "models: school does not exist in the database" // ErrSquadInvalid is returned when the provided squad does not exist in the database. ErrSquadInvalid modelError = "models: squad does not exist in the database" // ErrSquadNotUnique modelError is returned when a squad Create is attempted and a squad with the same SchoolID and Category // combination exists in the database. ErrSquadNotUnique modelError = "models: squad for this school and category already exists" // ErrMatchInvalid is returned when the provided match for a bout does not exist in the database. ErrMatchInvalid modelError = "models: match provided does not exist in the database" // ErrBoutPosInvalid is returned when the position of a bout is not in the range [0,8]. ErrBoutPosInvalid modelError = "models: bout position must be an integer from 1 through 9" // ErrEventInvalid is returned when the event associated with a match does not exist in the database. ErrEventInvalid modelError = "models: event provided does not exist in the database" // ErrRoundInvalid is returned when a match's round is greater than the number of rounds of the event to which the match belongs. ErrRoundInvalid modelError = "models: round must be between 1 and the number of rounds in the match, inclusive" // ErrSquadsSame is returned when the two squads in a match are the same squad. ErrSquadsSame modelError = "models: squads in a match must be different" // ErrSquadLeftInvalid is returned when the squad in a match does not exist in the database. ErrSquadLeftInvalid modelError = "models: Team A does not have such a squad in the database" // ErrSquadRightInvalid is returned when the squad in a match does not exist in the database. ErrSquadRightInvalid modelError = "models: Team B does not have such a squad in the database" // ErrSquadsDiffCategory is returned when two squads of different categories are listed as participants of the same match. ErrSquadsDiffCategory modelError = "models: Team A and Team B are of different categories" // ErrSquadsSameSchool is returned when two squads from the same school are listed as participants of the same match. ErrSquadsSameSchool modelError = "models: Team A and Team B are from the same school" // ErrWrongNumberOfBouts is returned when more or less than 9 bouts are associated with a match. ErrWrongNumberOfBouts modelError = "models: matches can only have 9 associated bouts" // ErrPluralityInvalid is returned when an invalid Plurality (individuals or squads) is used. ErrPluralityInvalid modelError = "models: plurality is invalid" // ErrNotYetImplemented is returned when a features has yet to be implemented. ErrNotYetImplemented modelError = "models: feature has not been implemented yet" // ErrWinnerLogic is returned when there's an undiagnosed problem in the winner selection logic. ErrWinnerLogic modelError = "models: error in winner selection logic" // ErrTokenInvalid is returned when password reset token is invalid. ErrTokenInvalid modelError = "models: token provided is not valid" // ErrUserIDRequired is returned when a user ID is required but no valid user ID is provided. ErrUserIDRequired modelError = "models: user ID is required" )
const ( // MenEpee is the men's epee category. MenEpee Category = "me" // MenFoil is the men's foil category. MenFoil = "mf" // MenSaber is the men's saber category. MenSaber = "ms" // WomenEpee is the women's epee category. WomenEpee = "we" // WomenFoil is the women's foil category. WomenFoil = "wf" // WomenSaber is the women's saber category. WomenSaber = "ws" )
const ( // PermLvlDefault defines the default permission level for a user. PermLvlDefault = iota // PermLvlAdmin defines the permission level for an admin. PermLvlAdmin // PermLvlSuperAdmin defines the permission level for a superadmin. PermLvlSuperAdmin )
Variables ¶
var ( // ErrPasswordTooShort is returned when a user tries to set a password that is less than passwordMinLen. ErrPasswordTooShort modelError = modelError(fmt.Sprintf("models: password must be at least %v characters long", strconv.Itoa(passwordMinLen))) // ErrRememberTooShort is required when a remember token is not at least rememberTokenMinLen bytes. ErrRememberTooShort privateError = privateError(fmt.Sprintf("models: remember token must be at least %v bytes long", strconv.Itoa(rememberMinLen))) )
var Categories = [6]Category{MenEpee, MenFoil, MenSaber, WomenEpee, WomenFoil, WomenSaber}
Categories is an array containing the six category options, for iteration.
var Pluralities = [2]Plurality{Squads, Individuals}
Pluralities is an array containing the two Plurality options.
Functions ¶
This section is empty.
Types ¶
type Bout ¶
type Bout struct { gorm.Model MatchID uint `gorm:"not_null"` Position uint `gorm:"not_null"` FencerIDLeft uint `gorm:"not_null"` FencerIDRight uint `gorm:"not_null"` ByeLeft bool `gorm:"-"` ByeRight bool `gorm:"-"` FencerNameLeft string `gorm:"-"` FencerNameRight string `gorm:"-"` SquadNameLeft string `gorm:"-"` SquadNameRight string `gorm:"-"` SquadIDLeft uint `gorm:"-"` SquadIDRight uint `gorm:"-"` ScoreLeft int `gorm:"not_null"` ScoreRight int `gorm:"not_null"` EventName string `gorm:"-"` Date time.Time `gorm:"-"` Round uint `gorm:"-"` }
Bout is the bout model. It has two fencer participants, a score for each fencer, and match data.
func (Bout) FencerIsWinner ¶
FencerIsWinner returns true if the fencerID provided won the bout, and false otherwise.
type BoutDB ¶
type BoutDB interface { // All returns a slice of all Bouts in the bouts table and a nil error; // or an empty slice and any error encountered. All() ([]Bout, error) // AllWithNames does the same as All, except that each bout has the fencer's names set and bye status. AllWithNames() ([]Bout, error) // ByID is used to look up a bout by its ID. // If the bout is found, it returns the bout and a nil error; otherwise it returns a nil bout and ErrNotFound. ByID(id uint) (*Bout, error) // ByIDWithNames is used to look up a bout by its ID in contexts where fencer names or bye status are important. // If the bout is found, it returns the bout and a nil error; otherwise it returns a nil bout and ErrNotFound. ByIDWithNames(id uint) (*Bout, error) // Create is used to make a new bout. Create(bout *Bout) error // Update is used to update a bout. Update(bout *Bout) error }
BoutDB is used to interact with the bouts database.
type BoutService ¶
type BoutService interface { BoutDB }
BoutService is a set of methods used to manipulate and work with the bout model. This is the head of an interface chain used to validate, normalize, and save data to the bouts database.
func NewBoutService ¶
func NewBoutService(db *gorm.DB, fs FencerService, ms MatchService) BoutService
NewBoutService initializes and returns a BoutService. It needs other services to validate existence of the corresponding resources.
type Category ¶
type Category string
Category is an enum for the participation category (combining gender and weapon) of a squad and other types. Categories are represented by two-character strings, where the first character represents gender (m or f) and the second represents weapon (e, f, or s). Use the string function to get the long-form name.
type Event ¶
type Event struct { gorm.Model Name string `gorm:"not_null"` Date time.Time `gorm:"not_null"` Rounds uint `gorm:"not_null"` }
Event is the event model. It requires a name, and can have a location, a start date, and an end date
type EventDB ¶
type EventDB interface { // All returns a slice of all Events in the events table and a nil error; // or an empty slice and any error encountered. All() ([]Event, error) // CurrentSeason returns a slice of all Events in the events table which are part of the current season, and // a nil error; or an empty slice and any error encountered. CurrentSeason() ([]Event, error) // PastSeasons returns a slice of all Events in the events table which are older than the current season, and a // nil error; or an empty slice and any error encountered. PastSeasons() ([]Event, error) // ByID is used to look up a event by its ID. // If the event is found, it returns the event and a nil error; otherwise it returns a nil event and ErrNotFound. ByID(id uint) (*Event, error) // MatchesByID is used to find all matches which are part of the event corresponding to id. MatchesByID(id uint) ([]Match, error) // Create is used to make a new event. Create(event *Event) error // Update is used to update an event. Update(event *Event) error // Delete is used to delete an event. Delete(id uint) error }
EventDB is used to interact with the events database.
type EventService ¶
type EventService interface { EventDB }
EventService is a set of methods used to manipulate and work with the event model. This is the head of an interface chain used to validate, normalize, and save data to the event database.
func NewEventService ¶
func NewEventService(db *gorm.DB, ssd time.Time) EventService
NewEventService initializes and returns an EventService.
type Fencer ¶
type Fencer struct { gorm.Model Name string `gorm:"not_null"` SquadID uint `gorm:"not_null"` Bye bool `gorm:"not_null;<-:create;DEFAULT:false"` Category Category `gorm:"-"` SchoolID uint `gorm:"-"` SchoolName string `gorm:"-"` Wins int `gorm:"-"` Losses int `gorm:"-"` TotalBouts int `gorm:"-"` }
Fencer is the fencer model. Fencers are the participants in bouts.
type FencerDB ¶
type FencerDB interface { // All returns a slice of all Fencers in the fencers table and a nil error; // or an empty slice and an error if one is encountered. // The fencers returned contain the associated data stored in squads and schools tables. (This is like ByIDWIthSquad for all fencers). All() ([]Fencer, error) // ByID is used to look up a fencer by their ID. // If the fencer is found, it returns the fencer and a nil error; otherwise it returns a nil fencer and ErrNotFound. ByID(id uint) (*Fencer, error) // ByIDWithSquad looks up a fencer by the id provided and joins with squads and schools tables to get all of the data associated with a fencer in those tables. ByIDWithSquad(id uint) (*Fencer, error) // ByCategory is used to look up Fencers by their Category. ByCategory(category Category) ([]Fencer, error) // BoutsByID is used to find all bouts in which a fencer has participated. // If the fencer exists and has participated in bouts, it returns a // non-empty []Bout and a nil error; otherwise, it will return a empty slice // and ErrNotFound. BoutsByID(id uint) ([]Bout, error) // BoutsByIDWithByes does the same as BoutsByID, but also returns BYEs. BoutsByIDWithByes(id uint) ([]Bout, error) // BoutsByIDCurrentSeason does the same as BoutsByIDWithByes, but only returns // bouts in the current season. BoutsByIDCurrentSeason(id uint) ([]Bout, error) // BoutsByIDs is used to find all bouts in which any fencer has participated. // If all of the fencers exist but have not participated in bouts, it returns a // non-empty []Bout and a nil error; otherwise, it will return a empty slice // and ErrNotFound. BoutsByIDs(ids []uint) ([]Bout, error) // Create is used to create a new fencer. Create(fencer *Fencer) error // Update is used to update an existing fencer. Update(fencer *Fencer) error // Delete removes an existing fencer from the database. Delete(id uint) error }
FencerDB is used to interact with the fencers database.
type FencerService ¶
type FencerService interface { FencerDB }
FencerService is a set of methods used to manipulate and work with the fencer model. This is the head of an interface chain used to validate, normalize, and save data to the fencers database.
func NewFencerService ¶
func NewFencerService(db *gorm.DB, sqs SquadService) FencerService
NewFencerService initializes and returns a FencerService.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
An Item is something we manage in a priority queue.
type Match ¶
type Match struct { gorm.Model EventID uint `gorm:"not_null"` Round uint `gorm:"not_null"` SquadIDLeft uint `gorm:"not_null"` SquadNameLeft string `gorm:"-"` SquadNameRight string `gorm:"-"` SquadIDRight uint `gorm:"not_null"` ScoreLeft uint ScoreRight uint EventName string `gorm:"-"` Date time.Time `gorm:"-"` Category Category `gorm:"-"` }
Match is the match model.
func (Match) SquadIsLoser ¶
SquadIsLoser returns true if the squadID provided lost the bout, and false otherwise.
func (Match) SquadIsWinner ¶
SquadIsWinner returns true if the squadID provided won the bout, and false otherwise.
type MatchDB ¶
type MatchDB interface { // ByID is used to look up a match by its ID. // If the match is found, it returns the match and a nil error; otherwise it returns a nil match and ErrNotFound. ByID(id uint) (*Match, error) // BoutsByID returns a slice of bouts associated with a match by the match's ID. BoutsByID(id uint) ([]Bout, error) // BoutsByIDWithByes does tthe same as BoutsByID and sets the bout.ByeLeft, bout.ByeRight. BoutsByIDWithByes(id uint) ([]Bout, error) // BoutsByIDWithNames does the same as BoutsByIDWithByes and sets the names of the fencers. BoutsByIDWithNames(id uint) ([]Bout, error) // Create is used to make a new match. Create(match *Match) error // Update is used to update a match. Update(match *Match) error // Delete is used to "soft-delete" a match by its id. Delete(id uint) error // DeleteBouts is used to "soft-delete" the bouts associated with a bout by the match id. DeleteBouts(id uint) error }
MatchDB is used to interact with the matches database.
type MatchService ¶
type MatchService interface { MatchDB }
MatchService is a set of methods used to manipulate and work with the match model. This is the head of an interface chain used to validate, normalize, and save data to the matches database.
func NewMatchService ¶
func NewMatchService(db *gorm.DB, es EventService, sqs SquadService) MatchService
NewMatchService initializes and returns a MatchService.
type Plurality ¶
type Plurality string
Plurality is an enum for the participation plurality (either individuals or squads).
const ( // Squads is the group plurality Squads Plurality = "squads" // Individuals is the singular plurality. Individuals = "individuals" )
type PriorityQueue ¶
type PriorityQueue []*Item
A PriorityQueue implements heap.Interface and holds Fencers.
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() any
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x any)
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type SchoolDB ¶
type SchoolDB interface { // All returns a slice of all Schools in the schools table and a nil error; or an empty slice and an error if one is encountered. All() ([]School, error) // ByID is used to look up a school by its ID. // If the school is found, it returns the school and a nil error; otherwise it returns a nil school and ErrNotFound. ByID(id uint) (*School, error) // SquadsByID returns a []Squad which enumerates the squads belonging to the school specified by the id parameter, and an error. // If the school does not have any squads in it, then SquadsByID will return an empty slice and a nil error. // It will return ErrNotFound if no school corresponds to the id, or other errors if the query is malformed. SquadsByID(id uint) ([]Squad, error) // FencersByID returns a slice of all fencers with school data. FencersByID(id uint) ([]Fencer, error) // Create is used to make a new school. Create(school *School) error // Update is used to update a school. Update(school *School) error // Delete is used to delete a school by its id. Delete(id uint) error }
SchoolDB is used to interact with the schools database.
type SchoolService ¶
type SchoolService interface { SchoolDB }
SchoolService is a set of methods used to manipulate and work with the school model. This is the head of an interface chain used to validate, normalize, and save data to the school database.
func NewSchoolService ¶
func NewSchoolService(db *gorm.DB) SchoolService
NewSchoolService initalizes and returns a SchoolService.
type Seeding ¶
type Seeding struct { Plurality Plurality Category Category Names []string SchoolNames []string IDs []uint Elos []int TotalGames []int CurrentGames []int }
Seeding represents a seeding a full seeding to be accessed by controllers. Ranking within seeding is implicit (0th index is 1st, Nth index is N+1th).
type SeedingService ¶
SeedingService is a set of methods used to manipulate and work with the match model. This is the head of an interface chain used to validate, normalize, and save data to the matches database.
func NewSeedingService ¶
func NewSeedingService(fs FencerService, sqs SquadService, minBouts int) SeedingService
NewSeedingService initializes and returns a SeedingService.
type Services ¶
type Services struct { User UserService Fencer FencerService Squad SquadService School SchoolService Bout BoutService Match MatchService Event EventService Seeding SeedingService // contains filtered or unexported fields }
Services is a struct storing all of the model services.
func NewServices ¶
func NewServices(cfgs ...ServicesConfig) (*Services, error)
NewServices initializes all of our services with connectionInfo.
func (*Services) AutoMigrate ¶
AutoMigrate will attempt to automatically migrate all tables.
func (*Services) DestructiveReset ¶
DestructiveReset drops all tables except for users and rebuilds them.
func (*Services) DestructiveResetUsers ¶
DestructiveResetUsers only drops the users table and rebuilds all tables.
type ServicesConfig ¶
ServicesConfig is a function type which takes a pointer to a Services.
func WithBout ¶
func WithBout() ServicesConfig
WithBout returns a function which creates a new FencerService.
func WithEvent ¶
func WithEvent(seasonStartDate time.Time) ServicesConfig
WithEvent returns a function which creates a new EventService.
func WithFencer ¶
func WithFencer() ServicesConfig
WithFencer returns a function which creates a new FencerService.
func WithGorm ¶
func WithGorm(dialect, connectionInfo string) ServicesConfig
WithGorm accepts dialect and connectionInfo and returns a function which opens a gorm database connection using the dialect and conectionInfo.
func WithLogMode ¶
func WithLogMode(mode bool) ServicesConfig
WithLogMode accepts mode and returns a function which enables gorm's log mode if mode == true.
func WithMatch ¶
func WithMatch() ServicesConfig
WithMatch returns a function which creates a new MatchService.
func WithSchool ¶
func WithSchool() ServicesConfig
WithSchool returns a function which creates a new SchoolService.
func WithSeeding ¶
func WithSeeding(minBouts int) ServicesConfig
WithSeeding returns a function which creates a new SeedingService. minBouts is the minimum number of bouts in which a fencer must participate to contribute toward squad seeding.
func WithSquad ¶
func WithSquad() ServicesConfig
WithSquad returns a function which creates a new SquadService.
func WithUser ¶
func WithUser(pepper, hmacKey string) ServicesConfig
WithUser accepts pepper and hmacKey and returns a function which passes them to the UserService.
type Squad ¶
type Squad struct { gorm.Model SchoolID uint `gorm:"not_null"` SchoolName string `gorm:"-"` Category Category `gorm:"not_null"` Wins int `gorm:"-"` Losses int `gorm:"-"` Draws int `gorm:"-"` }
Squad is the squad model.
type SquadDB ¶
type SquadDB interface { // ByID is used to look up a squad by its ID. // If the squad is found, it returns the squad and a nil error; otherwise it returns a nil squad and ErrNotFound. ByID(id uint) (*Squad, error) // ByIDWithSchoolName is used to look up a squad and the name of its school by the squad's ID. // If the squad is found, it returns the squad with SchoolName set and a nil error; otherwise it returns a nil squad and ErrNotFound. ByIDWithSchoolName(id uint) (*Squad, error) // BySchoolIDAndCategory is used to look up a squad by its school ID and category. // If the squad is found, it returns the squad and a nil error; otherwise it returns a nil squad and ErrNotFound. BySchoolIDAndCategory(schoolID uint, category Category) (*Squad, error) // ByCategory is used to look up all squads in a category. // If no squads are found, an empty slice is returned. ByCategory(category Category) ([]Squad, error) // FencersByID is used to look up a squad's fencers by the squad's ID. FencersByID(id uint) ([]Fencer, error) // FencersByIDWithByes is ued to look up a squad's bye fencers by the squad's ID. FencersByIDWithByes(id uint) ([]Fencer, error) // MatchesByIDs is used to look up all matches any squad in a slice of squads has participate in. MatchesByIDs(ids []uint) ([]Match, error) // MatchesByID is used to find all matches in which a squad has participated. // If the squad exists and has participated in matches, it returns a non-empty []Match and a nil error; otherwise, it will return // an empty slice and ErrNotFound. MatchesByID(id uint) ([]Match, error) // MatchesByIDCurrentSeason does the same as MatchesByID, but only returns matches in the current season. MatchesByIDCurrentSeason(id uint) ([]Match, error) // Create is used to make a new squad. Create(squad *Squad) error // Update is used to update a squad. Update(squad *Squad) error // Delete is used to update a squad. Delete(id uint) error }
SquadDB is used to interact with the squads database.
type SquadService ¶
type SquadService interface { SquadDB }
SquadService is a set of methods used to manipulate and work with the squad model. This is the head of an interface chain used to validate, normalize, and save data to the matches database.
func NewSquadService ¶
func NewSquadService(db *gorm.DB, ss SchoolService) SquadService
NewSquadService initializes and returns a SquadService.
type User ¶
type User struct { gorm.Model Name string `gorm:"not null"` Email string `gorm:"not null;unique_index"` Password string `gorm:"-"` PasswordHash string `gorm:"not null"` Remember string `gorm:"-"` RememberHash string `gorm:"not null;unique_index"` PermissionLvl int `gorm:"not null"` }
User is the user model, used to pass user data around, as well as save and retrieve users.
type UserDB ¶
type UserDB interface { // Methods for retrieving groups of users All() ([]User, error) // Methods for querying for single users ByID(id uint) (*User, error) ByEmail(email string) (*User, error) ByRemember(token string) (*User, error) // Methods for altering users Create(user *User) error Update(user *User) error Delete(id uint) error }
UserDB is used to interact with the users database.
For pretty much all single user queries: If the user is found, we will return a nil error. If the user is not found, we will return ErrNotFound. If there is another error, we will return an error with more information about what went wrong. This may not be an error generated by the models package.
For single user queries, any error but ErrNotFound should probably result in a 500 error.
type UserService ¶
type UserService interface { // Authenticate will verify the provided email address and password are correct. If they are correct, // the user corresponding to that email address will be returned. Otherwise, you will receive either // ErrLoginInvalid if the details do not match or another error if something went wrong. Authenticate(email, password string) (*User, error) // InitiateReset will complete all the model-related tasks // to start the password reset process for the user with // the provided email address. Once completed, it will // return the token, or an error if there was one. InitiateReset(email string) (string, error) // CompleteReset will complete all the model-related tasks // to complete the password reset process for the user that // the token matches, including updating that user's pw. // If the token has expired, or if it is invalid for any // other reason the ErrTokenInvalid error will be returned. CompleteReset(token, newPw string) (*User, error) UserDB }
UserService is a set of methods used to manipulate and work with the user model. This is the head of an interface chain used to validate, normalize, and finally save data.
func NewUserService ¶
func NewUserService(db *gorm.DB, pepper, hmacKey string) UserService
NewUserService initializes a new UserService as the head of an interface chain with a userValidator as the next node.