data

package
v0.0.0-...-c4ed5c6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: Unlicense Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
)

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record not found")
	ErrEditConflict   = errors.New("edit conflict")
)
View Source
var AnonymousUser = &User{}
View Source
var (
	ErrDuplicatedEmail = errors.New("duplicate email")
)
View Source
var ErrInvalidRuntimeFormat = fmt.Errorf("invalid runtime format")

Functions

func ValidateEmail

func ValidateEmail(v *validator.Validator, email string)

func ValidateFilters

func ValidateFilters(v *validator.Validator, f Filters)

func ValidateMovie

func ValidateMovie(v *validator.Validator, movie *Movie)

func ValidatePasswordPlaintext

func ValidatePasswordPlaintext(v *validator.Validator, password string)

func ValidateTokenPlaintext

func ValidateTokenPlaintext(v *validator.Validator, tokenPlaintext string)

func ValidateUser

func ValidateUser(v *validator.Validator, user *User)

Types

type Filters

type Filters struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafeList []string
}

func (Filters) SortColumn

func (f Filters) SortColumn() string

func (Filters) SortDirection

func (f Filters) SortDirection() string

type Metadata

type Metadata struct {
	CurrentPage  int `json:"current_page,omitempty"`
	PageSize     int `json:"page_size,omitempty"`
	TotalRecords int `json:"total_records,omitempty"`
	FirstPage    int `json:"first_page,omitempty"`
	LastPage     int `json:"last_page,omitempty"`
}

type Models

type Models struct {
	Movies      MovieModel
	Users       UserModel
	Tokens      TokenModel
	Permissions PermissionsModel
}

func NewModels

func NewModels(db *sql.DB) 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"`
}

type MovieModel

type MovieModel struct {
	DB *sql.DB
}

func (MovieModel) Delete

func (m MovieModel) Delete(id int64) error

func (MovieModel) Get

func (m MovieModel) Get(id int64) (*Movie, error)

func (MovieModel) GetAll

func (m MovieModel) GetAll(title string, genres []string, filters Filters) ([]*Movie, Metadata, error)

func (MovieModel) Insert

func (m MovieModel) Insert(movie *Movie) error

func (MovieModel) Update

func (m MovieModel) Update(movie *Movie) error

type Password

type Password struct {
	// contains filtered or unexported fields
}

func (*Password) Matches

func (p *Password) Matches(plainTextPassword string) (bool, error)

func (*Password) Set

func (p *Password) Set(plainTextPassword string) error

type Permissions

type Permissions []string

func (Permissions) Include

func (p Permissions) Include(code string) bool

type PermissionsModel

type PermissionsModel struct {
	DB *sql.DB
}

func (PermissionsModel) AddForUser

func (m PermissionsModel) AddForUser(userID int64, codes ...string) error

func (PermissionsModel) GetAllForUser

func (m PermissionsModel) GetAllForUser(userID int64) (Permissions, error)

type Runtime

type Runtime int32

func (Runtime) MarshalJSON

func (r Runtime) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaler for the Runtime type. This method is called by the json.Marshal() function and it returns the JSON representation of the Runtime type. It needs to be wrapped in double quotes, otherwise it won't be interpreted as a JSON String and we'll receive a runtime error similar to:\n json: error calling MarshalJSON for type data.Runtime: invalid character 'm' after top-level value

func (*Runtime) UnmarshalJSON

func (r *Runtime) UnmarshalJSON(jsonValue []byte) error

Implement a UnmarshalJSON() method on the Runtime type so that it satisfies the json.Unmarshaler interface. IMPORTANT: Because UnmarshalJSON() needs to modify the receiver (our Runtime type), we must use a pointer receiver for this to work correctly. Otherwise, we will only be modifying a copy (which is then discarded when this method returns).

type Token

type Token struct {
	Plaintext string    `json:"token"`
	Hash      []byte    `json:"-"`
	UserID    int64     `json:"-"`
	Expiry    time.Time `json:"expiry"`
	Scope     string    `json:"-"`
}

type TokenModel

type TokenModel struct {
	DB *sql.DB
}

func (TokenModel) DeleteAllForUser

func (m TokenModel) DeleteAllForUser(userID int64, scope string) error

DeleteAllForUser deletes all tokens for a specific user and scope.

func (TokenModel) Insert

func (m TokenModel) Insert(token *Token) error

func (TokenModel) New

func (m TokenModel) New(userID int64, ttl time.Duration, scope string) (*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

func (u *User) IsAnonymous() bool

type UserModel

type UserModel struct {
	DB *sql.DB
}

func (*UserModel) GetByEmail

func (m *UserModel) GetByEmail(email string) (*User, error)

func (UserModel) GetForToken

func (m UserModel) GetForToken(tokenScope, tokenPlaintext string) (*User, error)

func (*UserModel) Insert

func (m *UserModel) Insert(user *User) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL