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 = "activate" ScopeAuthentication = "authentication" )
Constants for token scope.
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") )
var ( PermissionMoviesRead = "movies:read" PermissionMoviesWrite = "movies:write" )
var AnonymousUser = &User{}
var (
ErrDuplicateEmail = errors.New("duplicate email")
)
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")
Functions ¶
func ValidateEmail ¶
ValidateEmail checks that the Email field is not an empty string and that it matches the regex for email addresses, validator.EmailRX.
func ValidateFilters ¶
func ValidateMovie ¶
ValidateMovie runs validation checks on the Movie type.
func ValidatePasswordPlaintext ¶
ValidatePasswordPlaintext validtes that the password is not an empty string and is between 8 and 72 bytes long.
func ValidateTokenPlaintext ¶
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
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 TokenModel ¶
func (TokenModel) DeleteAllForUser ¶
func (m TokenModel) DeleteAllForUser(scope string, userID int64) error
func (TokenModel) Insert ¶
func (m TokenModel) Insert(token *Token) error
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 the User details from the database based on the user's email address. Because we have a UNIQUE constraint on the email column, this query will only return one record, or none at all, upon which we return a ErrRecordNotFound error).
func (UserModel) GetForToken ¶
func (UserModel) Insert ¶
Insert inserts a new record in the users table in our database for the user. Note, that the id, created_at, and version fields are all automatically generated by our database, so we use use the RETURNING clause to read them into the User struct after the insert. Also, we check if our table already contains the same email address and if so return ErrDuplicateEmail error.