Created
November 7, 2018 12:04
-
-
Save gavinzhou/6aa014eff7fdf48372cc31585d84141c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package setting | |
import ( | |
"time" | |
"github.com/kelseyhightower/envconfig" | |
) | |
type DBConfig struct { | |
DBHost string `envconfig:"DBHost"` | |
Username string `envconfig:"Username"` | |
Password string `envconfig:"Password"` | |
Database string `envconfig:"Database"` | |
} | |
type ServerConfig struct { | |
HTTPPort int `envconfig:"PORT"` | |
ReadTimeout time.Duration `envconfig:"READTIMEOUT"` | |
WriteTimeout time.Duration `envconfig:"WRITETIMEOUT"` | |
} | |
type AppConfig struct { | |
RunMode string `envconfig:"RUNMODE"` | |
PageSize int `envconfig:"PAGESIZE"` | |
JWTSecret string `envconfig:"JWTSECRET` | |
} | |
type Config struct { | |
DBConfig | |
ServerConfig | |
AppConfig | |
} | |
func NewConfig() (Config, error) { | |
var config Config | |
err := envconfig.Process("", &config) | |
if err != nil { | |
return Config{}, err | |
} | |
return config, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment