Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Commit 6d429b5

Browse files
author
Barnaby Keene
committed
removed verbose mode and all prints
1 parent 84c96aa commit 6d429b5

File tree

4 files changed

+10
-33
lines changed

4 files changed

+10
-33
lines changed

configor.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ type Configor struct {
1919
type Config struct {
2020
Environment string
2121
EnvironmentPrefix string
22-
Verbose bool
2322

2423
// In case of json files, this field will be used only when compiled with
2524
// go 1.10 or later.
2625
// This field will be ignored when compiled with go versions lower than 1.10.
2726
ErrorOnUnmatchedKeys bool
2827
}
2928

30-
// New initializes a configuration loader
29+
// New initialises a configuration loader
3130
func New(config *Config) *Configor {
3231
if config == nil {
3332
config = &Config{}
@@ -54,9 +53,6 @@ func (configor *Configor) Load(config interface{}, files ...string) (err error)
5453
}
5554

5655
for _, file := range configFiles {
57-
if configor.Config.Verbose {
58-
fmt.Println("loading configuration from", file)
59-
}
6056
if err := UnmarshalFile(config, file, configor.ErrorOnUnmatchedKeys); err != nil {
6157
return err
6258
}

configor_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"reflect"
99
"testing"
1010

11+
"github.com/BurntSushi/toml"
1112
"gopkg.in/yaml.v2"
1213

13-
"github.com/BurntSushi/toml"
14-
"github.com/jinzhu/configor"
14+
"github.com/Southclaws/configor"
1515
)
1616

1717
type Anonymous struct {
@@ -396,7 +396,7 @@ func TestLoadConfigurationByEnvironmentSetByConfig(t *testing.T) {
396396
t.Errorf("result should be load configurations by environment correctly")
397397
}
398398

399-
if Configor.GetEnvironment() != "production" {
399+
if Configor.Environment != "production" {
400400
t.Errorf("configor's environment should be production")
401401
}
402402
}
@@ -471,7 +471,7 @@ func TestOverwriteConfigurationWithEnvironmentThatSetByConfig(t *testing.T) {
471471
defer os.Setenv("APP1_DB_Name", "")
472472

473473
var result Config
474-
var Configor = configor.New(&configor.Config{ENVPrefix: "APP1"})
474+
var Configor = configor.New(&configor.Config{EnvironmentPrefix: "APP1"})
475475
Configor.Load(&result, file.Name())
476476

477477
var defaultConfig = generateDefaultConfig()
@@ -581,15 +581,3 @@ func TestAnonymousStruct(t *testing.T) {
581581
}
582582
}
583583
}
584-
585-
func TestENV(t *testing.T) {
586-
if configor.ENV() != "test" {
587-
t.Errorf("Env should be test when running `go test`, instead env is %v", configor.ENV())
588-
}
589-
590-
os.Setenv("CONFIGOR_ENV", "production")
591-
defer os.Setenv("CONFIGOR_ENV", "")
592-
if configor.ENV() != "production" {
593-
t.Errorf("Env should be production when set it with CONFIGOR_ENV")
594-
}
595-
}

decode.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,16 @@ func (configor *Configor) processTags(config interface{}, prefixes ...string) (e
8282
}
8383

8484
if envName == "" {
85-
envNames = append(envNames, strings.Join(append(prefixes, fieldStruct.Name), "_")) // Configor_DB_Name
86-
envNames = append(envNames, strings.ToUpper(strings.Join(append(prefixes, fieldStruct.Name), "_"))) // CONFIGOR_DB_NAME
85+
envNames = append(envNames, strings.Join(append(prefixes, fieldStruct.Name), "_"))
86+
envNames = append(envNames, strings.ToUpper(strings.Join(append(prefixes, fieldStruct.Name), "_")))
8787
} else {
8888
envNames = []string{envName}
8989
}
9090

91-
if configor.Config.Verbose {
92-
fmt.Printf("Trying to load struct `%v`'s field `%v` from env %v\n", configType.Name(), fieldStruct.Name, strings.Join(envNames, ", "))
93-
}
94-
9591
// Load From Shell ENV
9692
for _, env := range envNames {
9793
if value := os.Getenv(env); value != "" {
98-
if configor.Config.Verbose {
99-
fmt.Printf("Loading configuration for struct `%v`'s field `%v` from env %v...\n", configType.Name(), fieldStruct.Name, env)
100-
}
101-
if err := yaml.Unmarshal([]byte(value), field.Addr().Interface()); err != nil {
94+
if err = yaml.Unmarshal([]byte(value), field.Addr().Interface()); err != nil {
10295
return err
10396
}
10497
break
@@ -108,7 +101,7 @@ func (configor *Configor) processTags(config interface{}, prefixes ...string) (e
108101
if isBlank := reflect.DeepEqual(field.Interface(), reflect.Zero(field.Type()).Interface()); isBlank {
109102
// Set default configuration if blank
110103
if value := fieldStruct.Tag.Get("default"); value != "" {
111-
if err := yaml.Unmarshal([]byte(value), field.Addr().Interface()); err != nil {
104+
if err = yaml.Unmarshal([]byte(value), field.Addr().Interface()); err != nil {
112105
return err
113106
}
114107
} else if fieldStruct.Tag.Get("required") == "true" {

unmarshal_json_1_10_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/jinzhu/configor"
12+
"github.com/Southclaws/configor"
1313
)
1414

1515
func TestUnmatchedKeyInJsonConfigFile(t *testing.T) {

0 commit comments

Comments
 (0)