Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/vendor/github.com/jinzhu/configor/configor.go
akuma06 713ab02450 Added configor as a new library (#1126)
* Added configor as a new library

Now config is a singleton. You only need to do config.Get() instead of doing config.Conf.

* Forgot godep save 🐤

* Fix accidental removal of }
2017-07-10 22:11:05 +10:00

65 lignes
1,3 Kio
Go

package configor
import (
"os"
"regexp"
)
type Configor struct {
*Config
}
type Config struct {
Environment string
ENVPrefix string
}
// New initialize a Configor
func New(config *Config) *Configor {
if config == nil {
config = &Config{}
}
return &Configor{Config: config}
}
// GetEnvironment get environment
func (configor *Configor) GetEnvironment() string {
if configor.Environment == "" {
if env := os.Getenv("CONFIGOR_ENV"); env != "" {
return env
}
if isTest, _ := regexp.MatchString("/_test/", os.Args[0]); isTest {
return "test"
}
return "development"
}
return configor.Environment
}
// Load will unmarshal configurations to struct from files that you provide
func (configor *Configor) Load(config interface{}, files ...string) error {
for _, file := range configor.getConfigurationFiles(files...) {
if err := processFile(config, file); err != nil {
return err
}
}
if prefix := configor.getENVPrefix(config); prefix == "-" {
return processTags(config)
} else {
return processTags(config, prefix)
}
}
// ENV return environment
func ENV() string {
return New(nil).GetEnvironment()
}
// Load will unmarshal configurations to struct from files that you provide
func Load(config interface{}, files ...string) error {
return New(nil).Load(config, files...)
}