postgres

package module
v0.0.0-...-7ed76d0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(hash, password []byte) error

func HashPassword

func HashPassword(password string) (string, error)

Types

type CreateUserRequest

type CreateUserRequest struct {
	Username string `json:"username" binding:"required" validate:"required,min=1,max=32,alphanum"`
	Email    string `json:"email" binding:"required" validate:"required,min=1,max=255,email"`
	Password string `json:"password" binding:"required" validate:"required,min=1,max=255"`
}

type DeleteUserRequest

type DeleteUserRequest struct {
	Username string `json:"username" binding:"required" validate:"required,min=1,max=32,alphanum"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username" binding:"required" validate:"required,min=1,max=32,alphanum"`
	Password string `json:"password" binding:"required" validate:"required,min=1,max=255"`
}

type Repository

type Repository struct {
	Db  *gorm.DB
	Ctx *context.Context
}

func NewRepository

func NewRepository(db *gorm.DB, ctx *context.Context) *Repository

func (*Repository) CheckUserPassword

func (r *Repository) CheckUserPassword(user *LoginRequest) error

func (*Repository) Close

func (r *Repository) Close() error

func (*Repository) Connect

func (r *Repository) Connect(dbHost string, dbUser string, dbPassword string, dbName string, dbPort int, sslmode string) (*gorm.DB, error)

func (*Repository) CreateUser

func (r *Repository) CreateUser(user *CreateUserRequest) error

func (*Repository) DeleteUser

func (r *Repository) DeleteUser(user *DeleteUserRequest) error

func (*Repository) GetAllUsers

func (r *Repository) GetAllUsers() ([]User, error)

func (*Repository) GetUser

func (r *Repository) GetUser(user *UserRequest) (*User, error)

func (*Repository) Login

func (r *Repository) Login(user *LoginRequest) error

func (*Repository) Migrate

func (r *Repository) Migrate() error

func (*Repository) Ping

func (r *Repository) Ping() error

func (*Repository) UpdateUser

func (r *Repository) UpdateUser(user *UpdateUserRequest) error

type UpdateUserRequest

type UpdateUserRequest struct {
	Username string `json:"username" binding:"required" validate:"required,min=1,max=32,alphanum"`
	Email    string `json:"email" validate:"omitempty,min=1,max=255,email"`
	Password string `json:"password" validate:"omitempty"`
}

type User

type User struct {
	Key        uint      `gorm:"primaryKey"`
	Username   string    `gorm:"type:varchar(32);unique;not null" validate:"required,min=1,max=32,alphanum"`
	Email      string    `gorm:"type:varchar(255);unique;not null" validate:"required,min=1,max=255,email"`
	Password   string    `gorm:"type:varchar(255);not null" validate:"required,min=1,max=255"`
	CreatedAt  time.Time `gorm:"autoCreateTime"`
	ModifiedAt time.Time `gorm:"autoUpdateTime"`
}

type UserRequest

type UserRequest struct {
	Username string `json:"username" binding:"required" validate:"required,min=1,max=32,alphanum"`
}

type UserResponse

type UserResponse struct {
	Id       int    `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Created  string `json:"created"`
	Modified string `json:"modified"`
}

Jump to

Keyboard shortcuts

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