mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
fix json tag parsing
This commit is contained in:
parent
dbe83c0fff
commit
ca77773fbf
@ -20,6 +20,10 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
|||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(v.Name()) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
arg := ®istry.Value{
|
arg := ®istry.Value{
|
||||||
Name: v.Name(),
|
Name: v.Name(),
|
||||||
Type: v.Name(),
|
Type: v.Name(),
|
||||||
@ -37,6 +41,9 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
|||||||
// if we can find a json tag use it
|
// if we can find a json tag use it
|
||||||
if tags := f.Tag.Get("json"); len(tags) > 0 {
|
if tags := f.Tag.Get("json"); len(tags) > 0 {
|
||||||
parts := strings.Split(tags, ",")
|
parts := strings.Split(tags, ",")
|
||||||
|
if parts[0] == "-" || parts[0] == "omitempty" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
val.Name = parts[0]
|
val.Name = parts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +52,11 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
|||||||
val.Name = v.Field(i).Name
|
val.Name = v.Field(i).Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// still no name then continue
|
||||||
|
if len(val.Name) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
arg.Values = append(arg.Values, val)
|
arg.Values = append(arg.Values, val)
|
||||||
}
|
}
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
|
Loading…
Reference in New Issue
Block a user