This restructures dbcore (now the db package) and jwtcore (now the jwt package) to use a single struct. There is now a state package, which contains a struct with the full application state. After this, instead of initializing the API routes directly in the main function, the state object gets passed, and the API routes get initialized with their accompanying code. One fix done to reduce memory usage and increase speed is that the validator object is now persistent across requests, instead of recreating it each time. This should speed things up slightly, and improve memory usage. One additional chore done is that the database models have been moved to be a seperate file from the DB initialization itself.
66 lines
924 B
Go
66 lines
924 B
Go
package db
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Backend struct {
|
|
gorm.Model
|
|
|
|
UserID uint
|
|
|
|
Name string
|
|
Description *string
|
|
Backend string
|
|
BackendParameters string
|
|
|
|
Proxies []Proxy
|
|
}
|
|
|
|
type Proxy struct {
|
|
gorm.Model
|
|
|
|
BackendID uint
|
|
UserID uint
|
|
|
|
Name string
|
|
Description *string
|
|
Protocol string
|
|
SourceIP string
|
|
SourcePort uint16
|
|
DestinationPort uint16
|
|
AutoStart bool
|
|
}
|
|
|
|
type Permission struct {
|
|
gorm.Model
|
|
|
|
PermissionNode string
|
|
HasPermission bool
|
|
UserID uint
|
|
}
|
|
|
|
type Token struct {
|
|
gorm.Model
|
|
|
|
UserID uint
|
|
|
|
Token string
|
|
DisableExpiry bool
|
|
CreationIPAddr string
|
|
}
|
|
|
|
type User struct {
|
|
gorm.Model
|
|
|
|
Email string `gorm:"unique"`
|
|
Username string `gorm:"unique"`
|
|
Name string
|
|
Password string
|
|
IsBot *bool
|
|
|
|
Permissions []Permission
|
|
OwnedProxies []Proxy
|
|
OwnedBackends []Backend
|
|
Tokens []Token
|
|
}
|