feat #4: add storage config in config file
This commit is contained in:
parent
7b1150c00b
commit
ccb417ad6a
2 changed files with 57 additions and 11 deletions
|
@ -40,12 +40,19 @@ const (
|
|||
ModeNet
|
||||
)
|
||||
|
||||
type BackendConfigType string
|
||||
|
||||
const (
|
||||
Memory BackendConfigType = "memory"
|
||||
SQLite BackendConfigType = "sqlite"
|
||||
)
|
||||
|
||||
type BackendConfig struct {
|
||||
Config *oidc.Config `json:"config"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"ID"`
|
||||
Type string `json:"type"`
|
||||
Local bool `json:"local"`
|
||||
Config *oidc.Config `json:"config"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"ID"`
|
||||
Type BackendConfigType `json:"type"`
|
||||
Local bool `json:"local"`
|
||||
}
|
||||
|
||||
type OpenConnectConfig struct {
|
||||
|
@ -54,6 +61,19 @@ type OpenConnectConfig struct {
|
|||
Issuer string `json:"issuer"`
|
||||
}
|
||||
|
||||
type StorageConfig struct {
|
||||
File string `json:"file"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Database string `json:"database"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Ssl struct {
|
||||
Mode string `json:"mode"`
|
||||
CaFile string `json:"caFile"`
|
||||
} `json:"ssl"`
|
||||
}
|
||||
|
||||
type jsonConf struct {
|
||||
Log struct {
|
||||
Level string `json:"level"`
|
||||
|
@ -64,6 +84,10 @@ type jsonConf struct {
|
|||
Mode string `json:"mode"`
|
||||
SockPath string `json:"sock"`
|
||||
} `json:"server"`
|
||||
Storage struct {
|
||||
StorageType string `json:"type"`
|
||||
Config *StorageConfig `json:"config"`
|
||||
} `json:"storage"`
|
||||
OpenConnectConfig *OpenConnectConfig `json:"openconnect"`
|
||||
}
|
||||
|
||||
|
@ -73,6 +97,8 @@ type AppConfig struct {
|
|||
Host string
|
||||
Port int
|
||||
SockPath string
|
||||
StorageType string
|
||||
StorageConfig *StorageConfig
|
||||
OpenConnectConfig *OpenConnectConfig
|
||||
}
|
||||
|
||||
|
@ -102,14 +128,17 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
|
|||
ac.Host = jsonConf.Server.Host
|
||||
ac.Port = jsonConf.Server.Port
|
||||
ac.OpenConnectConfig = jsonConf.OpenConnectConfig
|
||||
ac.StorageType = jsonConf.Storage.StorageType
|
||||
ac.StorageConfig = jsonConf.Storage.Config
|
||||
return nil
|
||||
}
|
||||
|
||||
var defaultConfig AppConfig = AppConfig{
|
||||
LogLevel: logrus.InfoLevel,
|
||||
ServerMode: ModeNet,
|
||||
Host: "0.0.0.0",
|
||||
Port: 5000,
|
||||
LogLevel: logrus.InfoLevel,
|
||||
ServerMode: ModeNet,
|
||||
Host: "0.0.0.0",
|
||||
Port: 5000,
|
||||
StorageType: "memory",
|
||||
}
|
||||
|
||||
func New(filepath string) (*AppConfig, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue