support metadata option
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
fade40754a
commit
59d6c26003
2
go.mod
2
go.mod
@ -2,4 +2,4 @@ module github.com/unistack-org/micro-client-http/v3
|
||||
|
||||
go 1.16
|
||||
|
||||
require github.com/unistack-org/micro/v3 v3.4.5
|
||||
require github.com/unistack-org/micro/v3 v3.4.8
|
||||
|
4
go.sum
4
go.sum
@ -5,8 +5,8 @@ github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||
github.com/unistack-org/micro/v3 v3.4.5 h1:4Rn6EkJz/web43XGZAPt4NtqDLV2SrYXZxdAfBKF9Ic=
|
||||
github.com/unistack-org/micro/v3 v3.4.5/go.mod h1:LXmPfbJnJNvL0kQs8HfnkV3Wya2Wb+C7keVq++RCZnk=
|
||||
github.com/unistack-org/micro/v3 v3.4.8 h1:9+qGlNHgChC3aMuFrtTFUtG55PEAjneSvplg7phwoCI=
|
||||
github.com/unistack-org/micro/v3 v3.4.8/go.mod h1:LXmPfbJnJNvL0kQs8HfnkV3Wya2Wb+C7keVq++RCZnk=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
9
http.go
9
http.go
@ -72,13 +72,20 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg
|
||||
if t, ok := opts.Context.Value(structTagsKey{}).([]string); ok && len(t) > 0 {
|
||||
tags = t
|
||||
}
|
||||
if md, ok := opts.Context.Value(metadataKey{}).(metadata.Metadata); ok {
|
||||
for k, v := range md {
|
||||
hreq.Header.Set(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
hreq.URL, err = u.Parse(ep)
|
||||
if err != nil {
|
||||
return nil, errors.BadRequest("go.micro.client", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if opts.AuthToken != "" {
|
||||
hreq.Header.Set("Authorization", opts.AuthToken)
|
||||
}
|
||||
if len(tags) == 0 {
|
||||
switch ct {
|
||||
default:
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -96,3 +97,9 @@ type structTagsKey struct{}
|
||||
func StructTags(tags []string) client.CallOption {
|
||||
return client.SetCallOption(structTagsKey{}, tags)
|
||||
}
|
||||
|
||||
type metadataKey struct{}
|
||||
|
||||
func Metadata(md metadata.Metadata) client.CallOption {
|
||||
return client.SetCallOption(metadataKey{}, md)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user