data

package
v0.0.0-...-5d75163 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record not found")
	ErrEditConflict   = errors.New("edit conflict")
)
View Source
var AnonymousUser = &User{}
View Source
var (
	ErrDuplicateEmail = errors.New("duplicate email")
)

Functions

func ValidateBlog

func ValidateBlog(v *validator.Validator, blog *Blog)

func ValidateEmail

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

func ValidateFilter

func ValidateFilter(v *validator.Validator, f Filter)

func ValidatePassword

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

func ValidateUser

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

Types

type Blog

type Blog struct {
	ID        int64     `json:"id"`
	CreatedAt time.Time `json:"-"`
	Title     string    `json:"title"`
	Body      string    `json:"body"`
	Category  []string  `json:"category"`
	Version   int32     `json:"version,omitempty"`
}

type BlogModel

type BlogModel struct {
	DB *sql.DB
}

func (BlogModel) Delete

func (b BlogModel) Delete(id int64) error

func (BlogModel) Get

func (b BlogModel) Get(id int64) (*Blog, error)

func (BlogModel) GetAll

func (b BlogModel) GetAll(title string, category []string, f Filter) ([]*Blog, Metadata, error)

func (BlogModel) Insert

func (b BlogModel) Insert(blog *Blog) error

func (BlogModel) Update

func (b BlogModel) Update(blog *Blog) error

type Filter

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

type Metadata

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

type Model

type Model struct {
	Blog interface {
		Insert(blog *Blog) error
		Get(id int64) (*Blog, error)
		Update(blog *Blog) error
		Delete(id int64) error
		GetAll(title string, category []string, f Filter) ([]*Blog, Metadata, error)
	}
	User interface {
	}
}

func NewModel

func NewModel(db *sql.DB) Model

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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