models

package
v0.0.0-...-8227220 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionFilter  = "$filter"
	OptionOrderBy = "$orderby"
	OptionTop     = "$top"
	OptionSkip    = "$skip"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	ReaderID       string
	RefreshTokenID string
	Role           string
	Expiry         time.Duration
}

type Author

type Author struct {
	ID        string    `json:"id" regex:"(?i)^[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}$"`
	FirstName string    `json:"first_name" regex:"^[\p{L}&\s-\\'’.]{2,256}$"`
	LastName  string    `json:"last_name" regex:"^[\p{L}&\s-\\'’.]{2,256}$"`
	CreatedAt time.Time `json:"created_at"`
}

type Book

type Book struct {
	ID       string `json:"id" sql:"id"`
	AuthorID string `json:"author_id" sql:"author_id" regex:"(?i)^[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}$"`
	Title    string `json:"title" sql:"title" regex:"^[[:graph:]]{1,256}$"`
	// TODO: Add ISBN
	Genre string `json:"genre" sql:"genre" regex:"^[[:graph:]]{1,256}$"`
	Rate  int    `json:"rate" sql:"rate" regex:"^([[:digit:]]|10)$"`
	Size  int    `json:"size" sql:"size" regex:"^[[:digit:]]{1,256}$"`
	Year  int    `json:"year" sql:"year" regex:"^[[:digit:]]{4}$"`
}

func (*Book) OK

func (b *Book) OK() error

type Credentials

type Credentials struct {
	Email    string `json:"email" regex:"(?i)(^[a-z0-9_.+-]+@[a-z0-9-]+\.[a-z0-9-.]+$)"`
	Password string `json:"password" regex:"^[[:graph:]]{8,256}$"`
}

func (*Credentials) Normalize

func (c *Credentials) Normalize()

func (*Credentials) OK

func (c *Credentials) OK() error

type DataFilter

type DataFilter struct {
	Filter  *Filter
	OrderBy string
	Top     int
	Skip    int
	URL     *url.URL
}

DataFilter represents a set of [OData](https://www.odata.org/getting-started/basic-tutorial/#queryData) query options to filter and sort data. It supports the following query options:

  • $filter: optional parameter that represents a filter operation with operations: 'and', 'or', 'eq', 'ne', 'gt', 'lt', 'ge', 'le'.
  • $orderby: optional parameter that represents a sorting column with operators: 'asc' and 'desc'.
  • $top: optional parameter that represents a limit of items from the resource.
  • $skip: optional parameter that represents an offset of records in the resource.

The names of fields must correspond to struct field names and should be provided in case-sensitive format.

Example: http://localhost:8080/books?$filter=Author eq 'Papa Karlo' and Title eq 'Pinocchio'&$orderby=Title desc&$skip=1&$top=10

TODO: add following properties: `from`, `to` (in UTC format), `in` Sequences (ids of sequences).

func NewDataFilter

func NewDataFilter[T any](u *url.URL) (*DataFilter, error)

NewDataFilter creates a new instance of *DataFilter of struct type T based on the OData query options present in the specified URL. The input of the OData query options will be validated during the process.

func (*DataFilter) UpdateURL

func (df *DataFilter) UpdateURL()

UpdateURL makes query on top of parent URL.

type Filter

type Filter struct {
	RawQuery string
	Head     *FilterNode
}

Filter represent linked lists of OData expressions.

type FilterNode

type FilterNode struct {
	Field       string
	Operator    string
	Conjunction string
	Value       string
	Next        *FilterNode
}

FilterNode represents OData expression.

type Logger

type Logger interface {
	Flush() error
	Level() string
	With(...any)
	Debugf(string, ...any)
	Debugw(string, ...any)
	Infof(string, ...any)
	Infow(string, ...any)
	Warnf(string, ...any)
	Warnw(string, ...any)
	Errorf(string, ...any)
	Errorw(string, ...any)
	// Fatal ... are essential for migrations.
	Fatal(...any)
	Fatalf(string, ...any)
	Print(...any)
	Println(...any)
	Printf(string, ...any)
}

Logger is designed for logging.

type Reader

type Reader struct {
	ID        string    `json:"id"` // regex:"(?i)^[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}$"
	FirstName string    `json:"first_name" regex:"^[\p{L}&\s-\\'’.]{2,256}$"`
	LastName  string    `json:"last_name" regex:"^[\p{L}&\s-\\'’.]{2,256}$"`
	Email     string    `json:"email" regex:"(?i)(^[a-z0-9_.+-]+@[a-z0-9-]+\.[a-z0-9-.]+$)"`
	Password  string    `json:"password" regex:"^[[:graph:]]{8,256}$"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
	DeletedAt time.Time `json:"deleted_at"`
}

func (*Reader) CheckPassword

func (r *Reader) CheckPassword(password string) error

func (*Reader) HashPassword

func (r *Reader) HashPassword() (err error)

func (*Reader) Normalize

func (r *Reader) Normalize()

func (*Reader) OK

func (r *Reader) OK() error

type RefreshToken

type RefreshToken struct {
	ID       string
	ReaderID string
	Expiry   time.Duration
}

type Token

type Token struct {
	ID     string
	UID    string
	Expiry time.Duration
}

type TokenPair

type TokenPair struct {
	AccessToken  string        `json:"access_token"`
	TokenType    string        `json:"token_type"`
	ExpiresIn    time.Duration `json:"expires_in"`
	RefreshToken string        `json:"refresh_token"`
}

Jump to

Keyboard shortcuts

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