Skip to content

Commit

Permalink
Set FillDefaultValues to public.
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik committed Sep 28, 2023
1 parent 79377ad commit 741d724
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion default.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func isUint(v reflect.Value) bool {
return false
}

func fillDefaultValues(config interface{}) error {
func FillDefaultValues(config interface{}) error {
v := reflect.ValueOf(config)
if v.Type().Kind() == reflect.Ptr {
v = v.Elem()
Expand Down
12 changes: 6 additions & 6 deletions default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestFillDefaultValues(t *testing.T) {
}
}{}

err := fillDefaultValues(config)
err := FillDefaultValues(config)
require.Nil(t, err)
require.Equal(t, uint(90), config.PID)
require.Equal(t, "debug", config.LogLevel)
Expand All @@ -38,38 +38,38 @@ func TestFillDefaultValues(t *testing.T) {
config2 := &struct {
Count int `yaconf:"default"`
}{}
err = fillDefaultValues(&config2)
err = FillDefaultValues(&config2)
require.Nil(t, err)

// Test invalid int
config3 := &struct {
Count int `yaconf:"default=yes"`
}{}
err = fillDefaultValues(&config3)
err = FillDefaultValues(&config3)
require.NotNil(t, err)
require.Equal(t, "yes is invalid value for int", err.Error())

// Test invalid uint
config4 := &struct {
Count uint `yaconf:"default=a"`
}{}
err = fillDefaultValues(&config4)
err = FillDefaultValues(&config4)
require.NotNil(t, err)
require.Equal(t, "a is invalid value for uint", err.Error())

// Test invalid duration
config5 := &struct {
Timeout time.Duration `yaconf:"default=22"`
}{}
err = fillDefaultValues(&config5)
err = FillDefaultValues(&config5)
require.NotNil(t, err)
require.Equal(t, "22 is invalid value for time.Duration", err.Error())

// Test invalid bool
config6 := &struct {
Debug bool `yaconf:"default=22"`
}{}
err = fillDefaultValues(&config6)
err = FillDefaultValues(&config6)
require.NotNil(t, err)
require.Equal(t, "22 is invalid value for bool", err.Error())

Expand Down
2 changes: 1 addition & 1 deletion yaconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Read(filename string, config interface{}) error {
return err
}

err = fillDefaultValues(config)
err = FillDefaultValues(config)
if err != nil {
return err
}
Expand Down

0 comments on commit 741d724

Please sign in to comment.