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 ValidatePassword(v *validator.Validator, password string)
- func ValidatePlainTextToken(v *validator.Validator, plainTextToken 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") ErrDuplicateEmail = errors.New("duplicate email") )
var AnonymousUser = &User{}
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")
ErrInvalidRuntimeFormat is an error that our UnmarshalJSON() method can return if we're unable to parse or convert the JSON string successfully.
Functions ¶
func ValidateEmail ¶
func ValidateFilters ¶
func ValidateMovie ¶
func ValidatePassword ¶
func ValidatePlainTextToken ¶
ValidatePlainTextToken() checks that the plaintext token is provided and is exactly 52 bytes long
func ValidateUser ¶
Types ¶
type Models ¶
type Models struct { Movies MovieModel Users UserModel Tokens TokenModel Permissions PermissionModel }
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() adds permisssion codes to a specific user
func (PermissionModel) GetAllForUser ¶
func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)
type Permissions ¶
type Permissions []string
Permissions type holds the permission files from the db
func (Permissions) Include ¶
func (p Permissions) Include(code string) bool
type Token ¶
type Token struct { PlainText string `json:"token"` Hash []byte `json:"-"` UserID int64 `json:"-"` Expiry time.Time `json:"expiry"` Scope string `json:"-"` }
Token type holds the data for an individual token. JSON tags control how the type fields appear when encoded into JSON
type TokenModel ¶
func (TokenModel) DeleteAllForUser ¶
func (m TokenModel) DeleteAllForUser(userID int64, scope string) error
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:"-"` Activated bool `json:"activated"` Version int `json:"-"` }
func (*User) IsAnonymous ¶
type UserModel ¶
func (UserModel) GetByEmail ¶
GetByEmail retrieves user details from the database based on the user's email address. Because we have a UNIQUE constraint on the email column, this SQL query will only return one record (or none at all, in which case we return a ErrRecordNotFound error).