Esempio n. 1
0
func New() (*Config, error) {
	c := Config{}
	if err := env.Process(&c); err != nil {
		return nil, err
	}
	arg.MustParse(&c)
	return &c, nil
}
Esempio n. 2
0
func newConfig() (*config, error) {
	cfg := &config{}
	if err := env.Process(cfg); err != nil {
		return cfg, err
	}

	return cfg, nil
}
Esempio n. 3
0
// HAL_NAME=hal
// HAL_PORT=
// HAL_ADAPTER=
func main() {
	// os.Setenv("IS_ENABLED", "asdf")
	c := &Config{}
	if err := env.Process(c); err != nil {
		fmt.Println("error:", err)
		return
		// panic(err)
	}
	fmt.Printf("name: %s, port: %d, adapter: %s, enabled: %v\n", c.Name, c.Port, c.Adapter, c.Enabled)
}
Esempio n. 4
0
// HAL_NAME=hal
// HAL_PORT=
// HAL_ADAPTER=
func main() {
	os.Setenv("NAME", "foo")
	os.Setenv("PORT", "9001")
	os.Setenv("ADAPTER", "shell")
	// os.Setenv("IS_ENABLED", "asdf")
	c := &Config{}
	if err := env.Process(c); err != nil {
		panic(err)
	}
	fmt.Printf("name: %s, port: %d, adapter: %s, enabled: %v\n", c.Name, c.Port, c.Adapter, c.Enabled)
}
Esempio n. 5
0
func newConfig() (*config, error) {
	cfg := &config{}
	if err := env.Process(cfg); err != nil {
		return cfg, err
	}

	if cfg.TestDBName == "" {
		cfg.TestDBName = cfg.DBName + "_test"
	}

	if cfg.TestDBUser == "" {
		cfg.TestDBUser = cfg.DBUser
	}

	if cfg.TestDBPassword == "" {
		cfg.TestDBPassword = cfg.DBPassword
	}

	if cfg.TestDBHost == "" {
		cfg.TestDBHost = cfg.DBHost
	}

	if cfg.TestDBName == cfg.DBName {
		return cfg, errors.New("test DB name same as DB name")
	}

	if cfg.BaseDir == "" {
		cfg.BaseDir = getDefaultBaseDir()
	}

	if cfg.PublicDir == "" {
		cfg.PublicDir = path.Join(cfg.BaseDir, "public")
	}

	if cfg.UploadsDir == "" {
		cfg.UploadsDir = path.Join(cfg.PublicDir, "uploads")
	}

	if cfg.ThumbnailsDir == "" {
		cfg.ThumbnailsDir = path.Join(cfg.UploadsDir, "thumbnails")
	}

	if cfg.TemplatesDir == "" {
		cfg.TemplatesDir = path.Join(cfg.BaseDir, "templates")
	}

	return cfg, nil
}