MCPcopy
hub / github.com/redis/go-redis / appendStructField

Function appendStructField

commands.go:111–136  ·  view source on GitHub ↗

appendStructField appends the field and value held by the structure v to dst, and returns the appended dst.

(dst []interface{}, v reflect.Value)

Source from the content-addressed store, hash-verified

109
110// appendStructField appends the field and value held by the structure v to dst, and returns the appended dst.
111func appendStructField(dst []interface{}, v reflect.Value) []interface{} {
112 typ := v.Type()
113 for i := 0; i < typ.NumField(); i++ {
114 tag := typ.Field(i).Tag.Get("redis")
115 if tag == "" || tag == "-" {
116 continue
117 }
118 name, opt, _ := strings.Cut(tag, ",")
119 if name == "" {
120 continue
121 }
122
123 field := v.Field(i)
124
125 // miss field
126 if omitEmpty(opt) && isEmptyValue(field) {
127 continue
128 }
129
130 if field.CanInterface() {
131 dst = append(dst, name, field.Interface())
132 }
133 }
134
135 return dst
136}
137
138func omitEmpty(opt string) bool {
139 for opt != "" {

Callers 1

appendArgFunction · 0.85

Calls 4

omitEmptyFunction · 0.85
isEmptyValueFunction · 0.85
TypeMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected