fixup path filling
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
9d955fc079
commit
a134383a53
2
go.mod
2
go.mod
@ -2,7 +2,7 @@ module go.unistack.org/micro-client-http/v3
|
|||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require go.unistack.org/micro/v3 v3.10.62
|
require go.unistack.org/micro/v3 v3.10.67
|
||||||
|
|
||||||
require (
|
require (
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
golang.org/x/sys v0.19.0 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -1,6 +1,6 @@
|
|||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
go.unistack.org/micro/v3 v3.10.62 h1:PCwLSt3W53UGosH/5qU3kU0iJxK8jlKOm9p4v/Zti5o=
|
go.unistack.org/micro/v3 v3.10.67 h1:Bk2VXsmMoKS2xkiultQS5WQCzsQlinYY+cAk4mAXi0U=
|
||||||
go.unistack.org/micro/v3 v3.10.62/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
go.unistack.org/micro/v3 v3.10.67/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
||||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
@ -25,8 +25,8 @@ func TestNestedPath(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if u.String() != "/api/v1/first/second?field1=fieldval" {
|
if s := u.String(); s != "/api/v1/first/second?field1=fieldval" {
|
||||||
t.Fatal("nested path error")
|
t.Fatalf("nested path error %s", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,8 +90,8 @@ func TestValidPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestInvalidPath(t *testing.T) {
|
func TestInvalidPath(t *testing.T) {
|
||||||
req := &request{Name: "vtolstov", Field1: "field1", Field2: "field2", Field3: 10}
|
req := &request{Name: "vtolstov", Field1: "field1", Field2: "field2", Field3: 10}
|
||||||
_, _, err := newPathRequest("/api/v1/{xname}/list", "GET", "", req, nil, nil)
|
s, _, err := newPathRequest("/api/v1/{xname}/list", "GET", "", req, nil, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("path param must not be filled")
|
t.Fatalf("path param must not be filled: %s", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
util.go
18
util.go
@ -169,18 +169,28 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
fld := msg
|
fld := msg
|
||||||
|
|
||||||
parts := strings.Split(k, ".")
|
parts := strings.Split(k, ".")
|
||||||
|
|
||||||
for idx := 0; idx < len(parts); idx++ {
|
for idx := 0; idx < len(parts); idx++ {
|
||||||
name := strings.Title(parts[idx])
|
var nfld interface{}
|
||||||
fld, err = rutil.StructFieldByName(fld, name)
|
if tags == nil {
|
||||||
if err != nil {
|
tags = []string{"json"}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
tagsloop:
|
||||||
|
for i := 0; i < len(tags); i++ {
|
||||||
|
nfld, err = rutil.StructFieldByTag(fld, tags[i], parts[idx])
|
||||||
|
if err == nil {
|
||||||
|
break tagsloop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
fld = nfld
|
||||||
if len(parts)-1 == idx {
|
if len(parts)-1 == idx {
|
||||||
isSet = true
|
isSet = true
|
||||||
fieldsmap[k] = fmt.Sprintf("%v", fld)
|
fieldsmap[k] = fmt.Sprintf("%v", fld)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !isSet {
|
if !isSet {
|
||||||
if val.Type().Kind() == reflect.Slice {
|
if val.Type().Kind() == reflect.Slice {
|
||||||
|
Loading…
Reference in New Issue
Block a user