Skip to content

Instantly share code, notes, and snippets.

@gavinzhou
Created November 7, 2018 12:04
Show Gist options
  • Save gavinzhou/6aa014eff7fdf48372cc31585d84141c to your computer and use it in GitHub Desktop.
Save gavinzhou/6aa014eff7fdf48372cc31585d84141c to your computer and use it in GitHub Desktop.
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