Skip to content

Conversation

@rs-frank
Copy link

type Info struct {
Ext string d:"aaa"
Name string d:"123"
}
type ShowInfo struct {
Name string d:"name"
Info
CreateTime time.Time d:"2020-01-02 03:04:01"
}

func TestBindDefaultValue(t *testing.T) {
var s ShowInfo
BindDefaultValue(&s)
log.Printf("%+v", s)
}

@mrwormhole
Copy link
Contributor

Hello @rs-frank, can you add more test cases for other default value types like bool, int, float?

@rs-frank
Copy link
Author

Hello @rs-frank, can you add more test cases for other default value types like bool, int, float?

func (s InfoForDefaultValueFunc) Default() reflect.Value {
return reflect.ValueOf(InfoForDefaultValueFunc{Name: "test name"})
}
type InfoForDefaultValueFunc struct {
Ext string d:"aaa"
Name string d:"123"
}
type Info struct {
Ext string d:"aaa"
Name string d:"123"
BoolFalse string d:"false"
BoolTrue string d:"true"
Float float32 d:"12.21"
Float64 float64 d:"12.51"
Number int d:"12"
}
type ShowInfo struct {
Name string d:"name"
Info
InfoForDefaultValueFunc InfoForDefaultValueFunc
CreateTime time.Time d:"2020-01-02 03:04:01"
}

func TestBindDefaultValue(t *testing.T) {
var s ShowInfo
BindDefaultValue(&s)
data, _ := json.Marshal(s)
log.Printf("%s", data)
}

@shyandsy
Copy link
Collaborator

shyandsy commented Apr 16, 2022

could you merge your commit, and rebase your code onto the develop branch?
and I will review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants