models

package
v0.1.24 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

type JSON json.RawMessage

JSON allows us to overload the json.Rawmessage type

func (*JSON) Scan

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

Scan scan value into Jsonb, implements sql.Scanner interface

func (JSON) Value

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 {
	ID            uuid.UUID              `gorm:"type:uuid;primarykey"`
	Username      string                 `gorm:"not null;unique" form:"username" json:"username,omitempty"`
	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"`
	Password      string                 `gorm:"not null" form:"password" json:"-"`
	CreatedAt     time.Time              `json:"created_at"`
	UpdatedAt     time.Time              `json:"updated_at"`
	DeletedAt     gorm.DeletedAt         `gorm:"index"`
}

User structure made exportable to be used with Gorm ORM

func (*User) BeforeCreate added in v0.1.22

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate allow gorm to create the UUID field

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.

func (*User) IsValid added in v0.1.22

func (u *User) IsValid() bool

IsValid checks if min required fields are filled

Jump to

Keyboard shortcuts

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