models

package
v0.0.0-...-914140b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(password string) ([]byte, error)

Hash password

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword password and the hashed password is the same

Types

type Config

type Config struct {
	Database Database `json:"db"`
	Service  Service  `json:"service"`
}

Config structure for the configuration file

func (*Config) Load

func (config *Config) Load(path string) (*Config, error)

Load config of service

type Database

type Database struct {
	Type         string `json:"type"`
	Host         string `json:"host"`
	Port         int    `json:"port"`
	User         string `json:"user"`
	DatabaseName string `json:"database"`
	Password     string `json:"password"`
}

Database structure configuration file format

type Service

type Service struct {
	Port      int    `json:"port"`
	APISecret string `json:"secret"`
	LogLevel  string `json:"loglevel"`
}

Service structure configuration file format

type User

type User struct {
	ID          uint32    `gorm:"primary_key;auto_increment" json:"id"`
	FirstName   string    `gorm:"size:255;not null;" json:"firstname"`
	LastName    string    `gorm:"size:255;not null;" json:"lastname"`
	Email       string    `gorm:"size:255;not null;unique" json:"email"`
	Password    string    `gorm:"size:100;not null;" json:"password"`
	PhoneNumber int       `gorm:"size:15;" json:"phone_number"`
	Country     string    `gorm:"size:100;" json:"country"`
	PostalCode  int       `gorm:"size:5;" json:"postal_code"`
	CreatedAt   time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt   time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

User structure for a user

func (*User) Create

func (u *User) Create(db *gorm.DB) (*User, error)

Create user and save in database

func (*User) Delete

func (u *User) Delete(db *gorm.DB, uid uint32) (int64, error)

Delete user in database

func (*User) FindByEmail

func (u *User) FindByEmail(db *gorm.DB, email string) (*User, error)

FindByEmail user by using email in database

func (*User) FindByID

func (u *User) FindByID(db *gorm.DB, uid uint32) (*User, error)

FindByID find user by ID

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword of user

func (*User) Update

func (u *User) Update(db *gorm.DB, uid uint32) (*User, error)

Update user in database

func (*User) Validate

func (u *User) Validate() error

Validate User is valid

func (*User) ValidateLogin

func (u *User) ValidateLogin() error

ValidateLogin basic authentication provided

Jump to

Keyboard shortcuts

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