database

package
v0.0.0-...-fb08230 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DbConn *sql.DB
)

DbConn stores the connexion to the database

Functions

func Connect

func Connect() error

Connect connection to database

func CreateAccount

func CreateAccount(userInput RequestRegister) (err error)

CreateAccount method for create an account with role operator

Types

type Config

type Config struct {
	DbHost     string `env:"DB_HOST"`
	DbName     string `env:"MYSQL_DATABASE"`
	DbUser     string `env:"MYSQL_USER"`
	DbPassword string `env:"MYSQL_PASSWORD"`
	DbConn     *sql.DB
}

Config for DB connection

type RequestRegister

type RequestRegister struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Email    string `json:"email"`
}

type Role

type Role uint8
const (
	OPERATOR     Role = 0x1
	ADMIN        Role = 0x1 << 1
	SYSTEM_ADMIN Role = 0x1 << 2
)

func (Role) IsAdmin

func (r Role) IsAdmin() bool

func (Role) IsOperator

func (r Role) IsOperator() bool

func (Role) IsSystemAdmin

func (r Role) IsSystemAdmin() bool

type User

type User struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"-"` // here is just for example
	Role     Role   `json:"role"`
}

func GetUserFromUsername

func GetUserFromUsername(username string) (user *User, err error)

GetUserFromUsername method for retrieve user from bdd

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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