Skip to content

Commit 88a613e

Browse files
committed
logic fix
1 parent d506d50 commit 88a613e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

clientv2/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,19 +651,19 @@ func (e *Encoder) isSkipOmitemptyField(v reflect.Value, field fieldInfo) bool {
651651
return false
652652
}
653653

654-
if !v.IsValid() {
655-
return true
654+
if !field.omitempty {
655+
return false
656656
}
657657

658-
if v.Kind() == reflect.Ptr && v.IsNil() {
658+
if !v.IsValid() {
659659
return true
660660
}
661661

662-
if field.omitempty && v.IsZero() {
662+
if v.Kind() == reflect.Ptr && v.IsNil() {
663663
return true
664664
}
665665

666-
return false
666+
return v.IsZero()
667667
}
668668

669669
// encodeStruct encodes a struct value

clientv2/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ func TestEncoder_encodeStruct(t *testing.T) {
970970
Name string `json:"name"`
971971
Age int64 `json:"age,omitempty"`
972972
Email *string `json:"email,omitempty"`
973+
Email2 *string `json:"email2"`
973974
Address Address `json:"address"`
974975
Tags []string `json:"tags,omitempty"`
975976
Nickname string `json:"nickname,omitempty"`
@@ -1002,6 +1003,7 @@ func TestEncoder_encodeStruct(t *testing.T) {
10021003
"name": "John",
10031004
"age": int64(30),
10041005
"email": "test@example.com",
1006+
"email2": nil,
10051007
"address": map[string]any{"city": "Tokyo", "country": "Japan", "zip": "123-4567"},
10061008
"tags": []any{"tag1", "tag2"},
10071009
"nickname": "Johnny",
@@ -1016,6 +1018,7 @@ func TestEncoder_encodeStruct(t *testing.T) {
10161018
enableOmitemptyTag: true,
10171019
want: map[string]any{
10181020
"name": "John",
1021+
"email2": nil,
10191022
"address": map[string]any{"city": "Tokyo"},
10201023
},
10211024
},
@@ -1030,6 +1033,7 @@ func TestEncoder_encodeStruct(t *testing.T) {
10301033
"name": "John",
10311034
"age": int64(0),
10321035
"email": nil,
1036+
"email2": nil,
10331037
"address": map[string]any{"city": "Tokyo", "country": "", "zip": nil},
10341038
"tags": []any{},
10351039
"nickname": "",

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/urfave/cli/v2"
1010
)
1111

12-
const version = "0.30.0"
12+
const version = "0.30.1"
1313

1414
var versionCmd = &cli.Command{
1515
Name: "version",

0 commit comments

Comments
 (0)