database

package
v0.0.0-...-43cf371 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: GPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(token string) (valid bool, member *model.Member, expiration time.Time)

Checks, if the given JWT is valid. Returns true if it is valid. Returns the member which belongs to the JWT. If the JWT is not valid, the member will be nil.

func CheckRoot

func CheckRoot()

Checks if root user and role exists. If not, it creates both, the password will be printed on configured log tool.

func Delete

func Delete(a interface{})

Deletes a single struct.

func Find

func Find(a interface{}) (exists bool)

Finds a single struct with an Id. Returns false if no struct exists with the given Id.

func FindAll

func FindAll(a interface{})

Finds a slice of structs.

func FindAllWhereEqual

func FindAllWhereEqual(a interface{}, field string, value interface{})

Finds a slice of structs with given condition.

func FindEventsRange

func FindEventsRange(events *[]*model.Event, from time.Time, to time.Time)

Finds all events in the given time range 'from' and 'to' do only check the date but not the time events which's date are equal 'from' or 'to' will be included

func Login

func Login(data *JWTData) (bool, string)

Does the login process. Returns true, if the login was successful. Returns the JWT for future request which require certain roles or permissions.

func PasswordHash

func PasswordHash(plainPassword string) string

Hashes a plaintext password and returns the hash.

func Register

func Register()

Registers all model structs from this project to the database.

func Save

func Save(a interface{})

Persists a single struct.

func TableCreate

func TableCreate(a interface{})

Creates tables for all registered structs, if not exist.

func UpdateCredentials

func UpdateCredentials(credentials *Credentials)

Persists the given credentials to the equivalent member into the

Types

type Credentials

type Credentials struct {
	MemberId int64  `json:"memberId"`
	Username string `json:"username"`
	Password string `json:"password"`
}

Defines the credentials with plain password.

type DBError

type DBError struct {
	// contains filtered or unexported fields
}

Generic error for all database related actions.

func (DBError) Error

func (d DBError) Error() string

type JWTData

type JWTData struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Defines the JWT data which has to be send to this server.

type JWTHeader

type JWTHeader struct {
	Algorithm string `json:"alg"`
	Type      string `json:"typ"`
}

Defines the JWT header.

type JWTPayload

type JWTPayload struct {
	MemberId   int64     `json:"memberId"`
	Expiration time.Time `json:"exp"`
}

Defines the JWT payload which is used to communicate between server and client.

type UserInfo

type UserInfo struct {
	Member     *model.Member `json:"member"`
	Roles      []*model.Role `json:"roles"`
	Expiration time.Time     `json:"exp"`
}

Jump to

Keyboard shortcuts

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