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 ValidatePlainPassword(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" )
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") )
var AnonymousUser = &User{}
var (
ErrDuplicateEmail = errors.New("duplicate email")
)
var ErrInvalidRuntime = fmt.Errorf("invalid runtime format")
Functions ¶
func ValidateEmail ¶
func ValidateFilters ¶
func ValidateMovie ¶
func ValidatePlainPassword ¶
func ValidateTokenPlainText ¶
func ValidateUser ¶
Types ¶
type Models ¶
type Models struct { Movies MovieModel Users UserModel Tokens TokenModel Permissions PermissionModel }
Models wraps the MovieMode and other 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"` // The version number starts at 1 and will be incremented each time the movie information is updated }
type MovieModel ¶
MovieModel provides access to the movie data store.
func (MovieModel) Delete ¶
func (m MovieModel) Delete(id int64) error
Delete deletes a specific record from the Movie table.
func (MovieModel) Get ¶
func (m MovieModel) Get(id int64) (*Movie, error)
Get fetches a specific record from the Movie table.
func (MovieModel) Insert ¶
func (m MovieModel) Insert(movie *Movie) error
Insert creates a new record in the Movie table.
func (MovieModel) Update ¶
func (m MovieModel) Update(movie *Movie) error
Update updates a specific record from the Movie table.
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
Include checks whether the Permissions slice contains a specific permission code.
type Runtime ¶
type Runtime int32
Runtime represents the runtime of a movie in minutes.
func (Runtime) MarshalJSON ¶
func (*Runtime) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON value into the Runtime type. We need pointer here in order to modify the receiver
type Token ¶
type Token struct { Plaintext string `json:"token"` Hash []byte `json:"-"` Expiry time.Time `json:"expiry"` Scope string `json:"-"` // contains filtered or unexported fields }
Token holds the data for an individual token. This includes the plaintext and hashed versions of the token, associated user ID, expiry time and scope.
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
Insert adds the data for a specific token to the tokens table.
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:"password"` Activated bool `json:"activated"` Version int `json:"-"` // The version number starts at 1 and will be incremented each time the movie information is updated }
func (*User) IsAnonymous ¶
IsAnonymous checks if a User instance is the AnonymousUser: an inactivated user with no ID, name, email or password