You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
442 B
32 lines
442 B
package config
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
)
|
|
|
|
// type DbConfig struct {
|
|
// Host string `envconfig:"DB_HOST"`
|
|
// Port int `envconfig:"DB_PORT"`
|
|
// }
|
|
|
|
type AppConfig struct {
|
|
Port int `envconfig:"APP_PORT"`
|
|
}
|
|
|
|
// ...
|
|
type Config struct {
|
|
// Db DbConfig
|
|
App AppConfig
|
|
}
|
|
|
|
func NewConfig() *Config {
|
|
c := Config{}
|
|
err := envconfig.Process("", &c)
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
|
|
return &c
|
|
}
|
|
|