models

package
v0.0.0-...-d3e0ec2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DBConfig       DBConfig
	JWTConfig      JWTConfig
	PasswordConfig PasswordConfig
}

func GetConfig

func GetConfig() (*Config, error)

GetConfig get singleton config and to load config from environment variables if necessary

type DBConfig

type DBConfig struct {
	MaxOpenConns int
	MaxIdleConns int
	// contains filtered or unexported fields
}

func (*DBConfig) GetPsqlConn

func (c *DBConfig) GetPsqlConn() string

GetPsqlConn get postgresql formatted connection string from configuration

type JWT

type JWT struct {
	AccessToken string `json:"access_token"`
}

type JWTConfig

type JWTConfig struct {
	PrivateKey ecdsa.PrivateKey
	PublicKey  ecdsa.PublicKey
}

type Message

type Message struct {
	ID         uint           `gorm:"primarykey"`
	CreatedAt  time.Time      `json:"-"`
	UpdatedAt  time.Time      `json:"-"`
	DeletedAt  gorm.DeletedAt `gorm:"index" json:"-"`
	OwnerID    uint
	Text       string `validate:"required"`
	Palindrome bool
	Recipients []User `gorm:"many2many:recipients;"`
}

func (*Message) Check

func (m *Message) Check()

Check all word play types

type PasswordConfig

type PasswordConfig struct {
	BcryptCost int
	PepperKey  []byte
}

type User

type User struct {
	gorm.Model
	Username    string `gorm:"unique"`
	PasswordKey []byte
	Messages    []Message `gorm:"foreignKey:OwnerID"`
}

func (*User) BeforeCreate

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

func (*User) CheckPassword

func (u *User) CheckPassword(passwordConfig *PasswordConfig, password []byte) error

CheckPassword compare not hashed password to password key

func (*User) GenerateJWT

func (u *User) GenerateJWT(jwtConfig *JWTConfig) (*JWT, error)

GenerateJWT generate jwt from user

func (*User) SetPassword

func (u *User) SetPassword(passwordConfig *PasswordConfig, password []byte) error

SetPassword set password key to hashed password

type UserLogin

type UserLogin struct {
	Username string `json:"username" xml:"username" form:"username" validate:"required"`
	Password string `json:"password" xml:"password" form:"password" validate:"required"`
}

Jump to

Keyboard shortcuts

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