db

package
v0.0.0-...-03ce9ab Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Define all Database Models here

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUserToGroup

func AddUserToGroup(username string, groupname string) error

func ConnectDB

func ConnectDB()

ConnectDB finds the correct database type and connects to it, then stores the pointer to the database handler in a variable

func CountFilesEntries

func CountFilesEntries() int64

func CreateFile

func CreateFile(name string, url string, comment string, blob string) (uint, error)

func CreateGroup

func CreateGroup(name string, email string, displayName string) error

func CreateStore

func CreateStore() sessions.Store

func CreateUser

func CreateUser(name string, passhash string, email string, displayName string) error

func DeleteGroup

func DeleteGroup(group Group) error

func DeleteUser

func DeleteUser(user User) error

func DeleteUserFromGroup

func DeleteUserFromGroup(username string, groupname string) error

func GetFileBlob

func GetFileBlob(id uint) string

func SetGroupDisplayName

func SetGroupDisplayName(group Group, name string) error

func SetGroupName

func SetGroupName(group Group, name string) error

func SetSimpleAttributes

func SetSimpleAttributes(id uint, mime string, size int64, sha256 string, sha1 string, md5 string, fileCmd string, extension string)

func SetUserDisplayName

func SetUserDisplayName(user User, name string) error

func SetUserEmail

func SetUserEmail(user User, email string) error

func SetUserName

func SetUserName(user User, name string) error

func SetUserPassHash

func SetUserPassHash(user User, hash string) error

func SetupDB

func SetupDB()

SetupDB checks if database has already been initialized and users exist, otherwise creates default users

func UpdateOriginalName

func UpdateOriginalName(id uint, originalName string)

Types

type Attachment

type Attachment struct {
	gorm.Model
	Name    string
	Comment string
	Blob    string
	FileID  uint
}

type Container

type Container struct {
	gorm.Model
	ContainerID string
	FileID      uint
	Status      int
	Port        int
	User        string
	Password    string //This has to be stored somewhere in plain text...
	ProxyFolder string
	Image       string
}

func ContainerByFolder

func ContainerByFolder(folder string) (*Container, error)

ContainerByFolder retrieves the Container by its folder UUID

func ContainerByID

func ContainerByID(id uint) *Container

ContainerByID gets the Container by its DB ID

func (*Container) Delete

func (container *Container) Delete() error

delete deltes the Container

func (*Container) New

func (container *Container) New() (*Container, error)

new creates a new and empty container

func (*Container) Save

func (container *Container) Save() error

save saves the (modified) container

type File

type File struct {
	gorm.Model
	Name        string
	Comment     *string
	StatusID    uint
	Blob        string
	Attachments []Attachment
	Properties  FileProperties
	CreatorID   uint
	AssigneeID  uint
}

func GetFileByBlob

func GetFileByBlob(blob string) *File

func GetFileByID

func GetFileByID(id uint) *File

func GetFileList

func GetFileList(page int, count int, c *gin.Context) ([]*File, error)

func (*File) Assignee

func (file *File) Assignee() User

func (*File) Creator

func (file *File) Creator() User

func (*File) Save

func (file *File) Save() error

save writes the given file to the Database

func (*File) Status

func (file *File) Status() Status

Status() gives the status of the file because GORM currently doesn't do ManyToOne, so to make this work well I'll have to ditch the ORM and go raw SQL

type FileProperties

type FileProperties struct {
	gorm.Model
	Mime         string
	OriginalName string
	Size         int64
	Sha256       string
	Sha1         string
	Md5          string
	FileCmd      string
	Extension    string
	Url          string
	FileID       uint
}

type Group

type Group struct {
	gorm.Model
	Name        string `grom:"unique;index"`
	DisplayName string
	Users       []User `gorm:"many2many:user_groups"`
}

func GetAllGroups

func GetAllGroups() ([]Group, error)

func GetGroupByID

func GetGroupByID(id int) (Group, error)

func GetGroupByName

func GetGroupByName(name string) (Group, error)

type Pod

type Pod struct {
	gorm.Model
	Name       string `grom:"unique;index"`
	Type       PodType
	BoundPorts []int
}

type PodType

type PodType struct {
	gorm.Model
	Name string
}

type Status

type Status struct {
	gorm.Model
	Name    string `grom:"unique;index"`
	Comment *string
}

func (*Status) Delete

func (status *Status) Delete() (*Status, error)

func (*Status) New

func (status *Status) New() (*Status, error)

func (*Status) Save

func (status *Status) Save() (*Status, error)

type User

type User struct {
	gorm.Model
	Name        string `gorm:"unique;index"`
	PassHash    string
	Email       string
	DisplayName string
	Groups      []Group `gorm:"many2many:user_groups"`
	Admin       bool
	Agent       bool
}

func GetAllUsers

func GetAllUsers() ([]User, error)

func GetUserByID

func GetUserByID(id int) (User, error)

func GetUserByName

func GetUserByName(name string) (User, error)

Jump to

Keyboard shortcuts

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