services

package
v0.0.0-...-f36648d Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB

DB database instance

View Source
var ErrAuthenticationFailed = errors.New("authentication failed")

ErrAuthenticationFailed --

View Source
var ErrRoleNotFound = errors.New("role not found")

ErrRoleNotFound --

View Source
var ErrUserNotFound = errors.New("user not found")

ErrUserNotFound --

View Source
var ErrUsernameAlreadyExists = errors.New("username already exists")

ErrUsernameAlreadyExists --

Logger zap sugared logger instance

View Source
var LoggerCore *zap.Logger

LoggerCore zap base logger instance

Functions

func AddRole

func AddRole(projectID int, userID string, canWrite bool) error

AddRole --

func ChangeUserPassword

func ChangeUserPassword(id string, newPassword string) error

ChangeUserPassword --

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash makes the hash from the password and compares to the input password

func DeleteDocument

func DeleteDocument(id int) error

DeleteDocument --

func DeleteProject

func DeleteProject(id int) error

DeleteProject --

func DeleteRole

func DeleteRole(projectID int, userID string) error

DeleteRole --

func DeleteUser

func DeleteUser(id string) error

DeleteUser --

func Finalize

func Finalize()

Finalize --

func GetSHA256Hex

func GetSHA256Hex(data []byte) string

GetSHA256Hex returns the sha256 hash of a []byte in hex format

func HashPassword

func HashPassword(password string) (string, error)

HashPassword makes the hash of the password using bcrypt

func Init

func Init()

Init --

func LoadAllProjectIDs

func LoadAllProjectIDs() ([]int, error)

LoadAllProjectIDs --

func LoadProjectIDsForUser

func LoadProjectIDsForUser(userID string) ([]int, error)

LoadProjectIDsForUser --

func LoggerMiddleware

func LoggerMiddleware() func(*gin.Context)

LoggerMiddleware gin middleware to log the requests

func PanicRecoveryMiddleware

func PanicRecoveryMiddleware() func(*gin.Context)

PanicRecoveryMiddleware gin middleware to recover from panic and log the error

func UpdateDocument

func UpdateDocument(id int, title string, body string, sortOrder int) error

UpdateDocument --

func UpdateProject

func UpdateProject(id int, title string, description string) error

UpdateProject --

func UpdateRole

func UpdateRole(projectID int, userID string, canWrite bool) error

UpdateRole --

func UpdateUser

func UpdateUser(id string, username string, admin bool) error

UpdateUser fields: Username, Admin

func UserFindIDByUserName

func UserFindIDByUserName(username string) (id string, err error)

UserFindIDByUserName returns the id of the user

Types

type Document

type Document struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	ID        int
	ProjectID int
	Title     string
	SortOrder int
	Body      string
}

Document document model

func CreateDocument

func CreateDocument(projectID int, title string, body string, sortOrder int) (document *Document, err error)

CreateDocument --

func LoadDocument

func LoadDocument(id int) (*Document, error)

LoadDocument --

func LoadDocuments

func LoadDocuments(projectID int) ([]*Document, error)

LoadDocuments loads all the documents of a project

type Project

type Project struct {
	CreatedAt   time.Time
	UpdatedAt   time.Time
	ID          int
	Title       string
	Description string
}

Project project model

func CreateProject

func CreateProject(title string, description string, user *User) (project *Project, err error)

CreateProject --

func LoadProject

func LoadProject(id int) (*Project, error)

LoadProject --

type Role

type Role struct {
	ProjectID int
	UserID    string
	CanWrite  bool
}

Role project user role model

func LoadProjectRoles

func LoadProjectRoles(projectID int) ([]*Role, error)

LoadProjectRoles --

func LoadRole

func LoadRole(projectID int, userID string) (*Role, error)

LoadRole --

func LoadUserRoles

func LoadUserRoles(userID string) ([]*Role, error)

LoadUserRoles --

type User

type User struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	ID        string
	Username  string
	Admin     bool
}

User user model

func AuthenticateUser

func AuthenticateUser(username string, password string) (user *User, err error)

AuthenticateUser --

func CreateUser

func CreateUser(username string, password string, admin bool, root bool) (*User, error)

CreateUser --

func LoadAllUsers

func LoadAllUsers() (result []*User, err error)

LoadAllUsers --

func LoadUser

func LoadUser(id string) (*User, error)

LoadUser --

Jump to

Keyboard shortcuts

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