Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateEmail(v *validator.Validator, email string)
- func ValidateFilters(v *validator.Validator, f Filters)
- func ValidateMovie(v *validator.Validator, movie *Movie)
- func ValidatePasswordPlaintext(v *validator.Validator, password string)
- func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext string)
- func ValidateUser(v *validator.Validator, user *User)
- type Filters
- type Metadata
- type Models
- type Movie
- type MovieModel
- type PermissionModel
- type Permissions
- type Runtime
- type Token
- type TokenModel
- type User
- type UserModel
Constants ¶
const ( ScopeActivation = "activation" ScopeAuthentication = "authentication" ScopePasswordReset = "password-reset" )
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") )
var AnonymousUser = &User{}
AnonymousUser represents a user that has not logged in to the system.
var ErrDuplicateEmail = errors.New("duplicate email")
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")
A valid runtime value looks like this: "<runtime> mins" The quotes are part of a valid value.
Functions ¶
func ValidateEmail ¶
func ValidateFilters ¶
func ValidateMovie ¶
func ValidateTokenPlaintext ¶
Check that the plaintext token has been provided and is exactly 26 bytes long. Encoding a 16-byte value under base-32 (like in generateToken) will produce a 26-character string.
func ValidateUser ¶
Types ¶
type Metadata ¶
type Metadata struct { CurrentPage int `json:"current_page,omitempty"` PageSize int `json:"page_size,omitempty"` FirstPage int `json:"first_page,omitempty"` LastPage int `json:"last_page,omitempty"` TotalRecords int `json:"total_records,omitempty"` }
Metadata holds extra fields that will be returned for paginated requests.
type Models ¶
type Models struct { Movies MovieModel Permissions PermissionModel Tokens TokenModel Users UserModel }
type Movie ¶
type Movie struct { ID int64 `json:"id"` CreatedAt time.Time `json:"-"` // Timestamp of when movie was first added to the database. Title string `json:"title"` Year int32 `json:"year,omitempty"` // Year of release. Runtime Runtime `json:"runtime,omitempty"` // Runtime in minutes. Genres []string `json:"genres,omitempty"` Version int32 `json:"version"` // Starts at 1, increments with every update. }
type MovieModel ¶
func (MovieModel) Delete ¶
func (m MovieModel) Delete(id int64) error
func (MovieModel) Insert ¶
func (m MovieModel) Insert(movie *Movie) error
func (MovieModel) Update ¶
func (m MovieModel) Update(movie *Movie) error
type PermissionModel ¶
func (PermissionModel) AddForUser ¶
func (m PermissionModel) AddForUser(userID int64, codes ...string) error
AddForUser will grant the given permissions to the given user.
func (PermissionModel) GetAllForUser ¶
func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)
GetAllForUser returns all permissions granted to a specific user. It uses the same pattern as MovieModel.GetAll.
type Permissions ¶
type Permissions []string
Permissions represents a list of permission codes. A user may have multiple permissions.
func (Permissions) Include ¶
func (p Permissions) Include(code string) bool
Include returns true if the given permission code is present in the permissions slice.
type Runtime ¶
type Runtime int32
func (Runtime) MarshalJSON ¶
func (*Runtime) UnmarshalJSON ¶
UnmarshalJSON expects the incoming value to be of the form: "<runtime> mins"
type TokenModel ¶
func (TokenModel) DeleteAllForUser ¶
func (m TokenModel) DeleteAllForUser(scope string, userID int64) error
DeleteAllForUser deletes all tokens for a specific user and scope.
func (TokenModel) Insert ¶
func (m TokenModel) Insert(token *Token) error
type User ¶
type User struct { ID int64 `json:"id"` CreatedAt time.Time `json:"created_at"` Name string `json:"name"` Email string `json:"email"` Password password `json:"-"` Activated bool `json:"activated"` Version int `json:"-"` }