本文整理汇总了Golang中github.com/jinzhu/configor.Load函数的典型用法代码示例。如果您正苦于以下问题:Golang Load函数的具体用法?Golang Load怎么用?Golang Load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getConfig
// Loading configuration from yaml file
func getConfig(c *cli.Context) (config.Config, error) {
yamlPath := c.GlobalString("config")
conf := config.Config{}
err := configor.Load(&conf, yamlPath)
return conf, err
}
示例2: TestLoadConfigurationByEnvironment
func TestLoadConfigurationByEnvironment(t *testing.T) {
config := generateDefaultConfig()
config2 := struct {
APPName string
}{
APPName: "config2",
}
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
defer os.Remove(file.Name())
configBytes, _ := yaml.Marshal(config)
config2Bytes, _ := yaml.Marshal(config2)
ioutil.WriteFile(file.Name()+".yaml", configBytes, 0644)
defer os.Remove(file.Name() + ".yaml")
ioutil.WriteFile(file.Name()+".production.yaml", config2Bytes, 0644)
defer os.Remove(file.Name() + ".production.yaml")
var result Config
os.Setenv("CONFIGOR_ENV", "production")
defer os.Setenv("CONFIGOR_ENV", "")
if err := configor.Load(&result, file.Name()+".yaml"); err != nil {
t.Errorf("No error should happen when load configurations, but got %v", err)
}
var defaultConfig = generateDefaultConfig()
defaultConfig.APPName = "config2"
if !reflect.DeepEqual(result, defaultConfig) {
t.Errorf("result should be load configurations by environment correctly")
}
}
}
示例3: TestResetPrefixToBlank
func TestResetPrefixToBlank(t *testing.T) {
config := generateDefaultConfig()
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
defer os.Remove(file.Name())
file.Write(bytes)
var result Config
os.Setenv("CONFIGOR_ENV_PREFIX", "-")
os.Setenv("APPNAME", "config2")
os.Setenv("DB_NAME", "db_name")
defer os.Setenv("CONFIGOR_ENV_PREFIX", "")
defer os.Setenv("APPNAME", "")
defer os.Setenv("DB_NAME", "")
configor.Load(&result, file.Name())
var defaultConfig = generateDefaultConfig()
defaultConfig.APPName = "config2"
defaultConfig.DB.Name = "db_name"
if !reflect.DeepEqual(result, defaultConfig) {
t.Errorf("result should equal to original configuration")
}
}
}
}
示例4: init
func init() {
if err := configor.Load(&Config, "config/database.yml", "config/smtp.yml"); err != nil {
panic(err)
}
View = render.New()
}
示例5: main
func main() {
filepaths, _ := filepath.Glob("db/seeds/data/*.yml")
if err := configor.Load(&Seeds, filepaths...); err != nil {
panic(err)
}
truncateTables()
createRecords()
}
示例6: init
func init() {
Fake, _ = faker.New("en")
Fake.Rand = rand.New(rand.NewSource(42))
rand.Seed(time.Now().UnixNano())
filepaths, _ := filepath.Glob("db/seeds/data/*.yml")
if err := configor.Load(&Seeds, filepaths...); err != nil {
panic(err)
}
}
示例7: init
func init() {
if err := configor.Load(&Config, "config/database.yml", "config/smtp.yml"); err != nil {
panic(err)
}
View = render.New()
htmlSanitizer := bluemonday.UGCPolicy()
View.RegisterFuncMap("raw", func(str string) template.HTML {
return template.HTML(htmlSanitizer.Sanitize(str))
})
}
示例8: init
func init() {
err := configor.Load(&config, "./config/verify_faces.json")
if err != nil {
myFatal("Read config file error: ", err)
}
for i, _ := range config.FaceRecServers {
if len(config.FaceRecServers[i].Url) == 0 {
config.FaceRecServers[i].Url = config.FaceRecServers[i].Host + ":" + config.FaceRecServers[i].Port
}
}
}
示例9: TestLoadNormalConfig
func TestLoadNormalConfig(t *testing.T) {
config := generateDefaultConfig()
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
file.Write(bytes)
var result Config
configor.Load(&result, file.Name())
if !reflect.DeepEqual(result, config) {
t.Errorf("result should equal to original configuration")
}
}
} else {
t.Errorf("failed to marshal config")
}
}
示例10: TestMissingRequiredValue
func TestMissingRequiredValue(t *testing.T) {
config := generateDefaultConfig()
config.DB.Password = ""
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
file.Write(bytes)
var result Config
if err := configor.Load(&result, file.Name()); err == nil {
t.Errorf("Should got error when load configuration missing db password")
}
}
} else {
t.Errorf("failed to marshal config")
}
}
示例11: TestLoadTOMLConfigWithTomlExtension
func TestLoadTOMLConfigWithTomlExtension(t *testing.T) {
config := generateDefaultConfig()
var buffer bytes.Buffer
if err := toml.NewEncoder(&buffer).Encode(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor.toml"); err == nil {
defer file.Close()
defer os.Remove(file.Name())
file.Write(buffer.Bytes())
var result Config
configor.Load(&result, file.Name())
if !reflect.DeepEqual(result, config) {
t.Errorf("result should equal to original configuration")
}
}
} else {
t.Errorf("failed to marshal config")
}
}
示例12: TestReadFromEnvironmentWithSpecifiedEnvName
func TestReadFromEnvironmentWithSpecifiedEnvName(t *testing.T) {
config := generateDefaultConfig()
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
file.Write(bytes)
var result Config
os.Setenv("DBPassword", "db_password")
configor.Load(&result, file.Name())
var defaultConfig = generateDefaultConfig()
defaultConfig.DB.Password = "db_password"
if !reflect.DeepEqual(result, defaultConfig) {
t.Errorf("result should equal to original configuration")
}
}
}
}
示例13: TestDefaultValue
func TestDefaultValue(t *testing.T) {
config := generateDefaultConfig()
config.APPName = ""
config.DB.Port = 0
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
file.Write(bytes)
var result Config
configor.Load(&result, file.Name())
if !reflect.DeepEqual(result, generateDefaultConfig()) {
t.Errorf("result should be set default value correctly")
}
}
} else {
t.Errorf("failed to marshal config")
}
}
示例14: TestAnonymousStruct
func TestAnonymousStruct(t *testing.T) {
config := generateDefaultConfig()
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
defer os.Remove(file.Name())
file.Write(bytes)
var result Config
os.Setenv("CONFIGOR_DESCRIPTION", "environment description")
defer os.Setenv("CONFIGOR_DESCRIPTION", "")
configor.Load(&result, file.Name())
var defaultConfig = generateDefaultConfig()
defaultConfig.Anonymous.Description = "environment description"
if !reflect.DeepEqual(result, defaultConfig) {
t.Errorf("result should equal to original configuration")
}
}
}
}
示例15: TestOverwriteConfigurationWithEnvironmentWithDefaultPrefix
func TestOverwriteConfigurationWithEnvironmentWithDefaultPrefix(t *testing.T) {
config := generateDefaultConfig()
if bytes, err := json.Marshal(config); err == nil {
if file, err := ioutil.TempFile("/tmp", "configor"); err == nil {
defer file.Close()
file.Write(bytes)
var result Config
os.Setenv("CONFIGOR_APPNAME", "config2")
os.Setenv("CONFIGOR_DB_NAME", "db_name")
configor.Load(&result, file.Name())
os.Setenv("CONFIGOR_APPNAME", "")
os.Setenv("CONFIGOR_DB_NAME", "")
var defaultConfig = generateDefaultConfig()
defaultConfig.APPName = "config2"
defaultConfig.DB.Name = "db_name"
if !reflect.DeepEqual(result, defaultConfig) {
t.Errorf("result should equal to original configuration")
}
}
}
}