feat: read config from environment

This commit is contained in:
Xhofe
2022-03-12 20:38:22 +08:00
parent b1d7a980d9
commit 9c2fc8e860
4 changed files with 34 additions and 19 deletions

View File

@ -1,36 +1,37 @@
package conf
type Database struct {
Type string `json:"type"`
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
Port int `json:"port"`
Name string `json:"name"`
TablePrefix string `json:"table_prefix"`
DBFile string `json:"db_file"`
SslMode string `json:"ssl_mode"`
Type string `json:"type" env:"A_LIST_DB_TYPE"`
User string `json:"user" env:"A_LIST_DB_USER"`
Password string `json:"password" env:"A_LIST_DB_PASS"`
Host string `json:"host" env:"A_LIST_DB_HOST"`
Port int `json:"port" env:"A_LIST_DB_PORT"`
Name string `json:"name" env:"A_LIST_DB_NAME"`
TablePrefix string `json:"table_prefix" env:"A_LIST_DB_TABLE_PREFIX"`
DBFile string `json:"db_file" env:"A_LIST_DB_FILE"`
SslMode string `json:"ssl_mode" env:"A_LIST_SLL_MODE"`
}
type Scheme struct {
Https bool `json:"https"`
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
Https bool `json:"https" env:"A_LIST_HTTPS"`
CertFile string `json:"cert_file" env:"A_LIST_CERT"`
KeyFile string `json:"key_file" env:"A_LIST_KEY"`
}
type CacheConfig struct {
Expiration int64 `json:"expiration"`
CleanupInterval int64 `json:"cleanup_interval"`
Expiration int64 `json:"expiration" env:"A_LIST_DB_EXPIRATION"`
CleanupInterval int64 `json:"cleanup_interval" env:"A_LIST_CLEANUP_INTERVAL"`
}
type Config struct {
Address string `json:"address"`
Port int `json:"port"`
Assets string `json:"assets"`
Force bool `json:"force"`
Address string `json:"address" env:"A_LIST_ADDR"`
Port int `json:"port" env:"A_LIST_PORT"`
Assets string `json:"assets" env:"A_LIST_ASSETS"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
Cache CacheConfig `json:"cache"`
TempDir string `json:"temp_dir"`
TempDir string `json:"temp_dir" env:"A_LIST_TEMP_DIR"`
}
func DefaultConfig() *Config {