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 Movies
- type PermissionModel
- type Permissions
- type Runtime
- type Token
- type TokenModel
- type User
- type UserModel
- type Users
Constants ¶
const ( ScopeActivation = "activation" ScopeAuthentication = "authentication" )
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") )
var AnonymousUser = &User{}
To represent a unactivated User
var (
ErrDuplicateEmail = errors.New("duplicate email")
)
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")
Functions ¶
func ValidateEmail ¶
func ValidateFilters ¶
func ValidateMovie ¶
func ValidateTokenPlaintext ¶
Check that the plaintext token has been provided and is exactly 26 bytes long.
func ValidateUser ¶
Types ¶
type Models ¶
type Models struct { Movies Movies 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
func (PermissionModel) GetAllForUser ¶
func (m PermissionModel) GetAllForUser(userID int64) (Permissions, error)
The GetAllForUser() method returns all permission codes for a specific user in a Permissions slice.
type Permissions ¶
type Permissions []string
"movies:read" and "movies:write") for a single user.
func (Permissions) Include ¶
func (p Permissions) Include(code string) bool
to check whether the Permissions slice contains a specific permission code.
type Token ¶
type Token struct { Plaintext string `json:"token"` Hash []byte `json:"-"` UserID int64 `json:"-"` Expiry time.Time `json:"expiry"` Scope string `json:"-"` }
only the Plaintext and Expiry field will be included when encoding a Token all other fields will be omitted
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:"-"` }
Define a User struct to represent an individual user. Importantly, notice how we are using the json:"-" struct tag to prevent the Password and Version fields appearing in any output when we encode it to JSON. Also notice that the Password field uses the custom password type defined below.
func (*User) IsAnonymous ¶
Check if a User instance is the AnonymousUser.