Skip to content

Commit

Permalink
feat: support option interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hui.wang committed Jun 26, 2024
1 parent 765ae26 commit 68e1a19
Show file tree
Hide file tree
Showing 11 changed files with 383 additions and 274 deletions.
2 changes: 1 addition & 1 deletion example/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func specOptionDeclareWithDefault() interface{} {
}
}

//go:generate optiongen --option_return_previous=true --slice_only_append=true
//go:generate optiongen --option_return_previous=true
func OnlyAppendOptionDeclareWithDefault() interface{} {
return map[string]interface{}{
"Address": []string{"10.0.0.1:6379", "10.0.0.2:6379"},
Expand Down
12 changes: 11 additions & 1 deletion example/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ package example

import "testing"

// interface test
type interfaceTest struct {
data []int64
}

func (i *interfaceTest) Apply(cc *Config) ConfigOption {
return AppendTestSliceInt64(1, 2, 3, 4).Apply(cc)
}

func TestNewConfig(t *testing.T) {
tc := NewFuncNameSpecified(false, "", WithTestMapIntInt(map[int]int{2: 4}))
it := &interfaceTest{data: []int64{1, 2, 3, 4}}
tc := NewFuncNameSpecified(false, "", WithTestMapIntInt(map[int]int{2: 4}), it)
if tc == nil {
t.Fatal("new config error")
}
Expand Down
Loading

0 comments on commit 68e1a19

Please sign in to comment.