add default config
This commit is contained in:
parent
1d312c9741
commit
557f3db4ed
|
@ -0,0 +1,53 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
Driver string `json:"driver" yaml:"driver"`
|
||||
DSN string `json:"dsn" yaml:"dsn"`
|
||||
}
|
||||
|
||||
type Redis struct {
|
||||
Addr string `json:"addr" yaml:"addr"`
|
||||
Password string `json:"password" yaml:"password"`
|
||||
DB int `json:"db" yaml:"db"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
TTL int64 `json:"ttl" yaml:"ttl"`
|
||||
Secret string `json:"secret" yaml:"secret"`
|
||||
AllowUrls []string `json:"allow_urls" yaml:"allowUrls"`
|
||||
}
|
||||
|
||||
type Translate struct {
|
||||
ClientKey string `json:"client_key" yaml:"clientKey"`
|
||||
ServerKey string `json:"server_key" yaml:"serverKey"`
|
||||
ValidateUrl string `json:"validate_url" yaml:"validateUrl"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Auth Auth `json:"auth" yaml:"auth"`
|
||||
Redis Redis `json:"redis" yaml:"redis"`
|
||||
Translate Translate `json:"translate" yaml:"translate"`
|
||||
Database Database `json:"database" yaml:"database"`
|
||||
}
|
||||
|
||||
func (c *Config) FromEnvironment() {
|
||||
c.Auth.Secret = os.Getenv("JWT_SECRET")
|
||||
c.Auth.TTL = 7200
|
||||
|
||||
c.Database.Driver = os.Getenv("DATABASE_DRIVER")
|
||||
c.Database.DSN = os.Getenv("DATABASE_DSN")
|
||||
if c.Database.Driver == "" {
|
||||
c.Database.Driver = "mysql"
|
||||
}
|
||||
|
||||
c.Redis.Addr = os.Getenv("REDIS_ADDRESS")
|
||||
c.Redis.Password = os.Getenv("REDIS_PASSWORD")
|
||||
if n, err := strconv.Atoi(os.Getenv("REDIS_DB")); err == nil {
|
||||
c.Redis.DB = n
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue