Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default value in slices #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions configor_test.go
Expand Up @@ -17,20 +17,21 @@ type Anonymous struct {
}

type testConfig struct {
APPName string `default:"configor" json:",omitempty"`
APPName string `default:"configor" json:"-"`
Hosts []string

DB struct {
Name string
User string `default:"root"`
Password string `required:"true" env:"DBPassword"`
Port uint `default:"3306" json:",omitempty"`
SSL bool `default:"true" json:",omitempty"`
Port uint `default:"3306" json:"-"`
SSL bool `default:"true" json:"-"`
}

Contacts []struct {
Name string
Email string `required:"true"`
Name string
Email string `required:"true"`
Active bool `default:"true" json:"-"`
}

Anonymous `anonymous:"true"`
Expand All @@ -46,8 +47,8 @@ func generateDefaultConfig() testConfig {
Name string
User string `default:"root"`
Password string `required:"true" env:"DBPassword"`
Port uint `default:"3306" json:",omitempty"`
SSL bool `default:"true" json:",omitempty"`
Port uint `default:"3306" json:"-"`
SSL bool `default:"true" json:"-"`
}{
Name: "configor",
User: "configor",
Expand All @@ -56,12 +57,14 @@ func generateDefaultConfig() testConfig {
SSL: true,
},
Contacts: []struct {
Name string
Email string `required:"true"`
Name string
Email string `required:"true"`
Active bool `default:"true" json:"-"`
}{
{
Name: "Jinzhu",
Email: "wosmvp@gmail.com",
Name: "Jinzhu",
Email: "wosmvp@gmail.com",
Active: true,
},
},
Anonymous: Anonymous{
Expand Down
6 changes: 3 additions & 3 deletions utils.go
Expand Up @@ -371,9 +371,6 @@ func (configor *Configor) load(config interface{}, watchMode bool, files ...stri
}
}

// process defaults
configor.processDefaults(config)

for _, file := range configFiles {
if configor.Config.Debug || configor.Config.Verbose {
fmt.Printf("Loading configurations from file '%v'...\n", file)
Expand All @@ -390,5 +387,8 @@ func (configor *Configor) load(config interface{}, watchMode bool, files ...stri
err = configor.processTags(config, prefix)
}

// process defaults
configor.processDefaults(config)

return err, true
}