models

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON added in v0.1.15

type JSON json.RawMessage

JSON allows us to overload the json.Rawmessage type

func (*JSON) Scan added in v0.1.15

func (j *JSON) Scan(src interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (JSON) Value added in v0.1.15

func (j JSON) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type MultiString

type MultiString []string

MultiString type is needed for gorm encapsulation

func (*MultiString) Scan

func (s *MultiString) Scan(src interface{}) error

Scan is needed for gorm encapsulation

func (MultiString) Value

func (s MultiString) Value() (driver.Value, error)

Value is needed for gorm encapsulation

type User

type User struct {
	gorm.Model
	Username      string                 `gorm:"not null;unique" form:"username" json:"username,omitempty"`
	Password      string                 `gorm:"not null" form:"password" json:"-"`
	Email         string                 `gorm:"not null;unique" json:"email,omitempty"`
	Roles         MultiString            `gorm:"type:text" json:"roles,omitempty"`
	Authorization string                 `json:"authorization,omitempty"`
	AuthorizedAt  time.Time              `json:"authorized_at,omitempty"`
	Token         JSON                   `gorm:"type:text" json:"token,omitempty"`
	Fields        map[string]interface{} `gorm:"-" json:"fields,omitempty"`
}

User structure made exportable to be used with Gorm ORM

func (*User) GetAuthorization

func (u *User) GetAuthorization() (string, error)

GetAuthorization returns the authorization method, e.g. Basic Authentication.

func (*User) GetAuthorizedAt

func (u *User) GetAuthorizedAt() (time.Time, error)

GetAuthorizedAt returns the exact time the client has been authorized for the "first" time.

func (*User) GetEmail

func (u *User) GetEmail() (string, error)

GetEmail returns the e-mail of (string,error) User.

func (*User) GetField

func (u *User) GetField(key string) (interface{}, error)

GetField optionally returns a dynamic field from the `Fields` field based on its key.

func (*User) GetID

func (u *User) GetID() (string, error)

GetID returns the ID of the User.

func (*User) GetPassword

func (u *User) GetPassword() (string, error)

GetPassword returns the raw password of the User.

func (*User) GetRoles

func (u *User) GetRoles() ([]string, error)

GetRoles returns the specific user's roles. Returns with `ErrNotSupported` if the Roles field is not initialized.

func (*User) GetToken

func (u *User) GetToken() ([]byte, error)

GetToken returns the token associated with this User. It may return empty if the User is not featured with a Token.

The implementation can change that behavior. Returns with `ErrNotSupported` if the Token field is empty.

func (*User) GetUsername

func (u *User) GetUsername() (string, error)

GetUsername returns the name of the User.

Jump to

Keyboard shortcuts

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