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, plaintextPassword 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 ¶
View Source
const ( ScopeActivation = "activation" ScopeAuthentication = "authentication" ScopePasswordReset = "password-reset" )
Constants for each kind of token scope.
Variables ¶
View Source
var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") )
View Source
var AnonymousUser = &User{}
A user is considered anonymous if no Authorization header is provided with their request.
View Source
var (
ErrDuplicateEmail = errors.New("duplicate email")
)
View Source
var ErrInvalidRuntimeValue = errors.New("invalid runtime value")
Functions ¶
func ValidateEmail ¶
func ValidateFilters ¶
Runs validation checks on the filter parameters provided by the client.
func ValidateMovie ¶
func ValidateTokenPlaintext ¶
func ValidateUser ¶
Types ¶
type Models ¶
type Models struct { Movies MovieModel Users UserModel Tokens TokenModel Permissions PermissionModel }
Holds all application db models.
type Movie ¶
type Movie struct { ID int64 `json:"id"` CreatedAt time.Time `json:"-"` Title string `json:"title"` Year int32 `json:"year,omitempty"` Runtime Runtime `json:"runtime,omitempty"` Genres []string `json:"genres,omitempty"` Version int32 `json:"version"` }
Represents a movie table in the database.
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
func (PermissionModel) GetAllForUser ¶
func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)
type Permissions ¶
type Permissions []string
func (Permissions) Include ¶
func (p Permissions) Include(code string) bool
type Runtime ¶
type Runtime int32
func (Runtime) MarshalJSON ¶
Implementation of json.Marshaler interface.
Encodes a Runtime of type int32 in the format of "<runtime> mins".
func (*Runtime) UnmarshalJSON ¶
Implementation of json.Unmarshaler interface.
Decodes a Runtime of format "<runtime> mins" into an int32 Runtime value.
type TokenModel ¶
func (TokenModel) DeleteAllForUser ¶
func (m TokenModel) DeleteAllForUser(scope string, userID int64) error
Deletes all tokens for a specific user and scope.
func (TokenModel) Insert ¶
func (m TokenModel) Insert(token *Token) error
Adds a new token to the tokens table.
type User ¶
type User struct { ID int64 `json:"id"` CreatedAt time.Time `json:"createdAt"` Name string `json:"name"` Email string `json:"email"` Password password `json:"-"` Activated bool `json:"activated"` Version int `json:"-"` }
func (*User) IsAnonymous ¶
type UserModel ¶
func (UserModel) GetForToken ¶
Click to show internal directories.
Click to hide internal directories.