database

package
v0.0.0-...-1790263 Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerStatusActive       = "active"
	ServerStatusProcessing   = "processing"
	ServerStatusUnauthorized = "unauthorized"
	ServerStatusUnavailable  = "unavailable"
)
View Source
const KeyPath = "storage/database/keys.json"
View Source
const ServerPath = "storage/database/servers.json"
View Source
const SettingPath = "storage/database/settings.json"

Variables

This section is empty.

Functions

This section is empty.

Types

type DataError

type DataError string

func (DataError) Error

func (de DataError) Error() string

type Database

type Database struct {
	SettingTable *SettingTable
	KeyTable     *KeyTable
	ServerTable  *ServerTable
}

func New

func New() (*Database, error)

type Key

type Key struct {
	Id      string `json:"id" validate:"required,hostname"`
	Cipher  string `json:"cipher" validate:"required,oneof=chacha20-ietf-poly1305 aes-128-gcm aes-256-gcm"`
	Secret  string `json:"secret" validate:"required,min=6,max=64"`
	Name    string `json:"name" validate:"required,min=1,max=64"`
	Quota   int64  `json:"quota" validate:"min=0"`
	Enabled bool   `json:"enabled"`
}

type KeyTable

type KeyTable struct {
	Keys      []*Key `json:"keys" validate:"required"`
	NextId    int64  `json:"next_id" validate:"required,min=1"`
	UpdatedAt int64  `json:"updated_at" validate:"min=0"`
}

func (*KeyTable) Delete

func (kt *KeyTable) Delete(id string) error

func (*KeyTable) Load

func (kt *KeyTable) Load() error

func (*KeyTable) Refill

func (kt *KeyTable) Refill(keys []Key) (err error)

func (*KeyTable) Save

func (kt *KeyTable) Save() (err error)

func (*KeyTable) Store

func (kt *KeyTable) Store(key Key) (*Key, error)

func (*KeyTable) Update

func (kt *KeyTable) Update(key Key) (*Key, error)

type Server

type Server struct {
	Id                 string `json:"id" validate:"required"`
	HttpHost           string `json:"http_host" validate:"required"`
	HttpPort           int    `json:"http_port" validate:"required,min=1,max=65536"`
	ShadowsocksEnabled bool   `json:"shadowsocks_enabled"`
	ShadowsocksHost    string `json:"shadowsocks_host"`
	ShadowsocksPort    int    `json:"shadowsocks_port" validate:"min=1,max=65536"`
	ApiToken           string `json:"api_token"`
	Status             string `json:"status"`
	SyncedAt           int64  `json:"synced_at" validate:"min=0"`
}

type ServerTable

type ServerTable struct {
	Servers   []*Server `json:"keys" validate:"required"`
	NextId    int64     `json:"next_id" validate:"required,min=1"`
	UpdatedAt int64     `json:"updated_at" validate:"min=0"`
}

func (*ServerTable) Delete

func (st *ServerTable) Delete(id string) error

func (*ServerTable) Find

func (st *ServerTable) Find(Id string) *Server

func (*ServerTable) Load

func (st *ServerTable) Load() error

func (*ServerTable) Save

func (st *ServerTable) Save() (err error)

func (*ServerTable) Store

func (st *ServerTable) Store(server Server) (*Server, error)

func (*ServerTable) Update

func (st *ServerTable) Update(server Server) (*Server, error)

type SettingTable

type SettingTable struct {
	AdminPassword      string  `json:"admin_password" validate:"required,min=8,max=32"`
	ApiToken           string  `json:"api_token" validate:"required,min=16,max=128"`
	ShadowsocksEnabled bool    `json:"shadowsocks_enabled"`
	ShadowsocksHost    string  `json:"shadowsocks_host" validate:"required,max=128"`
	ShadowsocksPort    int     `json:"shadowsocks_port" validate:"required,min=1,max=65536"`
	ExternalHttps      string  `json:"external_https"`
	ExternalHttp       string  `json:"external_http" validate:"required"`
	TrafficRatio       float64 `json:"traffic_ratio" validate:"required,min=1"`
}

func (*SettingTable) Load

func (st *SettingTable) Load() error

func (*SettingTable) Save

func (st *SettingTable) Save() error

Jump to

Keyboard shortcuts

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