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" )
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") )
var AnonymousUser = &User{}
var (
ErrDuplicateEmail = errors.New("duplicate email")
)
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")
ErrInvalidRuntimeFormat 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 ValidateTokenPlaintext ¶
Check that the plaintext token has been provided and is exactly 52 bytes long.
func ValidateUser ¶
Types ¶
type Models ¶
type Models struct { Movies MovieModel Permissions PermissionModel Tokens TokenModel Users UserModel }
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 Add the provided permission codes for a specific user. Notice that we're using a variadic parameter for the codes so that we can assign multiple permissions in a single call.
func (PermissionModel) GetAllForUser ¶
func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)
GetAllForUser method returns all permission codes for a specific user in a Permissions slice. The code in this method should feel very familiar --- it uses the standard pattern that we've already seen before for retrieving multiple data rows in an SQL query.
type Permissions ¶
type Permissions []string
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 struct to hold 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 ¶
Define the TokenModel type.
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:"-"` Activated bool `json:"activated"` Version int `json:"-"` }
func (*User) IsAnonymous ¶
type UserModel ¶
Create a UserModel struct which wraps the connection pool.