Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
3cbc879769 | |||
05add422d1 | |||
|
b4970ee807 | ||
|
f4c91686f4 | ||
ee9b7493e3 | |||
|
0182d6ab56 | ||
d99e97090c | |||
8de7912a91 | |||
6ccb40bab0 | |||
2b16a8a7a6 | |||
|
d051256839 | ||
68b32989fc | |||
21a41a8e03 | |||
9150958044 | |||
|
e358db44ca |
13
.github/stale.sh
vendored
13
.github/stale.sh
vendored
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash -ex
|
|
||||||
|
|
||||||
export PATH=$PATH:$(pwd)/bin
|
|
||||||
export GO111MODULE=on
|
|
||||||
export GOBIN=$(pwd)/bin
|
|
||||||
|
|
||||||
#go get github.com/rvflash/goup@v0.4.1
|
|
||||||
|
|
||||||
#goup -v ./...
|
|
||||||
#go get github.com/psampaz/go-mod-outdated@v0.6.0
|
|
||||||
go list -u -m -mod=mod -json all | go-mod-outdated -update -direct -ci || true
|
|
||||||
|
|
||||||
#go list -u -m -json all | go-mod-outdated -update
|
|
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -34,10 +34,9 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v2
|
||||||
continue-on-error: true
|
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
version: v1.30
|
version: v1.39
|
||||||
# Optional: working directory, useful for monorepos
|
# Optional: working directory, useful for monorepos
|
||||||
# working-directory: somedir
|
# working-directory: somedir
|
||||||
# Optional: golangci-lint command line arguments.
|
# Optional: golangci-lint command line arguments.
|
||||||
|
3
.github/workflows/pr.yml
vendored
3
.github/workflows/pr.yml
vendored
@@ -34,10 +34,9 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: lint
|
- name: lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v2
|
||||||
continue-on-error: true
|
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
version: v1.30
|
version: v1.39
|
||||||
# Optional: working directory, useful for monorepos
|
# Optional: working directory, useful for monorepos
|
||||||
# working-directory: somedir
|
# working-directory: somedir
|
||||||
# Optional: golangci-lint command line arguments.
|
# Optional: golangci-lint command line arguments.
|
||||||
|
44
.golangci.yml
Normal file
44
.golangci.yml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
run:
|
||||||
|
concurrency: 4
|
||||||
|
deadline: 5m
|
||||||
|
issues-exit-code: 1
|
||||||
|
tests: true
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
govet:
|
||||||
|
check-shadowing: true
|
||||||
|
enable:
|
||||||
|
- fieldalignment
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- govet
|
||||||
|
- deadcode
|
||||||
|
- errcheck
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- typecheck
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
- bodyclose
|
||||||
|
- gci
|
||||||
|
- goconst
|
||||||
|
- gocritic
|
||||||
|
- gosimple
|
||||||
|
- gofmt
|
||||||
|
- gofumpt
|
||||||
|
- goimports
|
||||||
|
- golint
|
||||||
|
- gosec
|
||||||
|
- makezero
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- nestif
|
||||||
|
- nilerr
|
||||||
|
- noctx
|
||||||
|
- prealloc
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
disable-all: false
|
2
go.mod
2
go.mod
@@ -2,4 +2,4 @@ module github.com/unistack-org/micro-client-http/v3
|
|||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require github.com/unistack-org/micro/v3 v3.3.9
|
require github.com/unistack-org/micro/v3 v3.3.16
|
||||||
|
9
go.sum
9
go.sum
@@ -5,12 +5,13 @@ 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/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/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/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||||
github.com/unistack-org/micro/v3 v3.3.9/go.mod h1:M3RGgKZX1OlTn0QB+3R1tlSoGwmEg6rb/Isr0lLYmjQ=
|
github.com/unistack-org/micro/v3 v3.3.16 h1:v0h/oC0TO2n1djQJeOjD2jNEqKkiykwI6cpflEVTlQE=
|
||||||
golang.org/x/net v0.0.0-20210326220855-61e056675ecf/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
github.com/unistack-org/micro/v3 v3.3.16/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo=
|
||||||
|
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
113
http.go
113
http.go
@@ -11,6 +11,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"github.com/unistack-org/micro/v3/broker"
|
||||||
@@ -18,23 +20,22 @@ import (
|
|||||||
"github.com/unistack-org/micro/v3/codec"
|
"github.com/unistack-org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"github.com/unistack-org/micro/v3/errors"
|
||||||
"github.com/unistack-org/micro/v3/metadata"
|
"github.com/unistack-org/micro/v3/metadata"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var DefaultContentType = "application/json"
|
||||||
DefaultContentType = "application/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
/*
|
||||||
func filterLabel(r []router.Route) []router.Route {
|
func filterLabel(r []router.Route) []router.Route {
|
||||||
// selector.FilterLabel("protocol", "http")
|
// selector.FilterLabel("protocol", "http")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
type httpClient struct {
|
type httpClient struct {
|
||||||
opts client.Options
|
opts client.Options
|
||||||
dialer *net.Dialer
|
|
||||||
httpcli *http.Client
|
httpcli *http.Client
|
||||||
init bool
|
init bool
|
||||||
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg interface{}, opts client.CallOptions) (*http.Request, error) {
|
func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg interface{}, opts client.CallOptions) (*http.Request, error) {
|
||||||
@@ -43,6 +44,7 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg
|
|||||||
|
|
||||||
var tags []string
|
var tags []string
|
||||||
var scheme string
|
var scheme string
|
||||||
|
|
||||||
u, err := url.Parse(addr)
|
u, err := url.Parse(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
hreq.URL = &url.URL{
|
hreq.URL = &url.URL{
|
||||||
@@ -52,7 +54,10 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg
|
|||||||
}
|
}
|
||||||
hreq.Host = addr
|
hreq.Host = addr
|
||||||
scheme = "http"
|
scheme = "http"
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// nolint: nestif
|
||||||
|
if scheme == "" {
|
||||||
ep := req.Endpoint()
|
ep := req.Endpoint()
|
||||||
if opts.Context != nil {
|
if opts.Context != nil {
|
||||||
if m, ok := opts.Context.Value(methodKey{}).(string); ok {
|
if m, ok := opts.Context.Value(methodKey{}).(string); ok {
|
||||||
@@ -67,7 +72,6 @@ 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 {
|
if t, ok := opts.Context.Value(structTagsKey{}).([]string); ok && len(t) > 0 {
|
||||||
tags = t
|
tags = t
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
hreq.URL, err = u.Parse(ep)
|
hreq.URL, err = u.Parse(ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -98,15 +102,9 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg
|
|||||||
return nil, errors.BadRequest("go.micro.client", err.Error())
|
return nil, errors.BadRequest("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var b []byte
|
b, err := cf.Marshal(nmsg)
|
||||||
|
if err != nil {
|
||||||
if ct == "x-www-form-urlencoded" {
|
return nil, errors.BadRequest("go.micro.client", err.Error())
|
||||||
fmt.Printf("XXXXX %#+v\n", nmsg)
|
|
||||||
} else if nmsg != nil {
|
|
||||||
b, err = cf.Marshal(nmsg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.BadRequest("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(b) > 0 {
|
if len(b) > 0 {
|
||||||
@@ -126,26 +124,19 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ct := req.ContentType()
|
ct := req.ContentType()
|
||||||
|
if len(opts.ContentType) > 0 {
|
||||||
|
ct = opts.ContentType
|
||||||
|
}
|
||||||
|
|
||||||
// set timeout in nanoseconds
|
// set timeout in nanoseconds
|
||||||
header.Set("Timeout", fmt.Sprintf("%d", opts.RequestTimeout))
|
header.Set("Timeout", fmt.Sprintf("%d", opts.RequestTimeout))
|
||||||
// set the content type for the request
|
// set the content type for the request
|
||||||
header.Set("Content-Type", ct)
|
header.Set("Content-Type", ct)
|
||||||
|
|
||||||
var cf codec.Codec
|
cf, err := h.newCodec(ct)
|
||||||
var err error
|
|
||||||
// get codec
|
|
||||||
switch ct {
|
|
||||||
case "x-www-form-urlencoded":
|
|
||||||
cf, err = h.newCodec(DefaultContentType)
|
|
||||||
default:
|
|
||||||
cf, err = h.newCodec(ct)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
return errors.InternalServerError("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
hreq, err := newRequest(addr, req, ct, cf, req.Body(), opts)
|
hreq, err := newRequest(addr, req, ct, cf, req.Body(), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -157,21 +148,21 @@ func (h *httpClient) call(ctx context.Context, addr string, req client.Request,
|
|||||||
hrsp, err := h.httpcli.Do(hreq.WithContext(ctx))
|
hrsp, err := h.httpcli.Do(hreq.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
case net.Error:
|
|
||||||
if err.Timeout() {
|
|
||||||
return errors.Timeout("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
case *url.Error:
|
case *url.Error:
|
||||||
if err, ok := err.Err.(net.Error); ok && err.Timeout() {
|
if err, ok := err.Err.(net.Error); ok && err.Timeout() {
|
||||||
return errors.Timeout("go.micro.client", err.Error())
|
return errors.Timeout("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
case net.Error:
|
||||||
|
if err.Timeout() {
|
||||||
|
return errors.Timeout("go.micro.client", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
return errors.InternalServerError("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
defer hrsp.Body.Close()
|
defer hrsp.Body.Close()
|
||||||
|
|
||||||
return parseRsp(ctx, hrsp, cf, rsp, opts)
|
return h.parseRsp(ctx, hrsp, rsp, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpClient) stream(ctx context.Context, addr string, req client.Request, opts client.CallOptions) (client.Stream, error) {
|
func (h *httpClient) stream(ctx context.Context, addr string, req client.Request, opts client.CallOptions) (client.Stream, error) {
|
||||||
@@ -187,22 +178,22 @@ func (h *httpClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
ct := req.ContentType()
|
ct := req.ContentType()
|
||||||
|
if len(opts.ContentType) > 0 {
|
||||||
|
ct = opts.ContentType
|
||||||
|
}
|
||||||
// set timeout in nanoseconds
|
// set timeout in nanoseconds
|
||||||
header.Set("Timeout", fmt.Sprintf("%d", opts.RequestTimeout))
|
if opts.StreamTimeout > time.Duration(0) {
|
||||||
|
header.Set("Timeout", fmt.Sprintf("%d", opts.StreamTimeout))
|
||||||
|
}
|
||||||
// set the content type for the request
|
// set the content type for the request
|
||||||
header.Set("Content-Type", ct)
|
header.Set("Content-Type", ct)
|
||||||
|
|
||||||
// get codec
|
// get codec
|
||||||
cf, err := h.newCodec(req.ContentType())
|
cf, err := h.newCodec(ct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
dialAddr := addr
|
|
||||||
u, err := url.Parse(dialAddr)
|
|
||||||
if err == nil && u.Scheme != "" && u.Host != "" {
|
|
||||||
dialAddr = u.Host
|
|
||||||
}
|
|
||||||
cc, err := (h.httpcli.Transport).(*http.Transport).DialContext(ctx, "tcp", addr)
|
cc, err := (h.httpcli.Transport).(*http.Transport).DialContext(ctx, "tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", fmt.Sprintf("Error dialing: %v", err))
|
return nil, errors.InternalServerError("go.micro.client", fmt.Sprintf("Error dialing: %v", err))
|
||||||
@@ -223,6 +214,13 @@ func (h *httpClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpClient) newCodec(ct string) (codec.Codec, error) {
|
func (h *httpClient) newCodec(ct string) (codec.Codec, error) {
|
||||||
|
h.RLock()
|
||||||
|
defer h.RUnlock()
|
||||||
|
|
||||||
|
if idx := strings.IndexRune(ct, ';'); idx >= 0 {
|
||||||
|
ct = ct[:idx]
|
||||||
|
}
|
||||||
|
|
||||||
if c, ok := h.opts.Codecs[ct]; ok {
|
if c, ok := h.opts.Codecs[ct]; ok {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@@ -289,7 +287,7 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
} else {
|
} else {
|
||||||
// got a deadline so no need to setup context
|
// got a deadline so no need to setup context
|
||||||
// but we need to set the timeout we pass along
|
// but we need to set the timeout we pass along
|
||||||
opt := client.WithRequestTimeout(d.Sub(time.Now()))
|
opt := client.WithRequestTimeout(time.Until(d))
|
||||||
opt(&callOpts)
|
opt(&callOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,22 +400,22 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
|
|||||||
func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
|
func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
|
||||||
// make a copy of call opts
|
// make a copy of call opts
|
||||||
callOpts := h.opts.CallOptions
|
callOpts := h.opts.CallOptions
|
||||||
for _, opt := range opts {
|
for _, o := range opts {
|
||||||
opt(&callOpts)
|
o(&callOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we already have a deadline
|
// check if we already have a deadline
|
||||||
d, ok := ctx.Deadline()
|
d, ok := ctx.Deadline()
|
||||||
if !ok {
|
if !ok && callOpts.StreamTimeout > time.Duration(0) {
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
// no deadline so we create a new one
|
// no deadline so we create a new one
|
||||||
ctx, cancel = context.WithTimeout(ctx, callOpts.RequestTimeout)
|
ctx, cancel = context.WithTimeout(ctx, callOpts.StreamTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
} else {
|
} else {
|
||||||
// got a deadline so no need to setup context
|
// got a deadline so no need to setup context
|
||||||
// but we need to set the timeout we pass along
|
// but we need to set the timeout we pass along
|
||||||
opt := client.WithRequestTimeout(d.Sub(time.Now()))
|
o := client.WithStreamTimeout(time.Until(d))
|
||||||
opt(&callOpts)
|
o(&callOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should we noop right here?
|
// should we noop right here?
|
||||||
@@ -429,10 +427,7 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
// make copy of call method
|
// make copy of call method
|
||||||
hstream, err := h.stream()
|
hstream := h.stream
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// wrap the call in reverse
|
// wrap the call in reverse
|
||||||
for i := len(callOpts.CallWrappers); i > 0; i-- {
|
for i := len(callOpts.CallWrappers); i > 0; i-- {
|
||||||
hstream = callOpts.CallWrappers[i-1](hstream)
|
hstream = callOpts.CallWrappers[i-1](hstream)
|
||||||
@@ -469,9 +464,9 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
|
|
||||||
call := func(i int) (client.Stream, error) {
|
call := func(i int) (client.Stream, error) {
|
||||||
// call backoff first. Someone may want an initial start delay
|
// call backoff first. Someone may want an initial start delay
|
||||||
t, err := callOpts.Backoff(ctx, req, i)
|
t, cerr := callOpts.Backoff(ctx, req, i)
|
||||||
if err != nil {
|
if cerr != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", cerr.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// only sleep if greater than 0
|
// only sleep if greater than 0
|
||||||
@@ -481,19 +476,19 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
|
|
||||||
node := next()
|
node := next()
|
||||||
|
|
||||||
stream, err := h.stream(ctx, node, req, callOpts)
|
stream, cerr := h.stream(ctx, node, req, callOpts)
|
||||||
|
|
||||||
// record the result of the call to inform future routing decisions
|
// record the result of the call to inform future routing decisions
|
||||||
if verr := h.opts.Selector.Record(node, err); verr != nil {
|
if verr := h.opts.Selector.Record(node, cerr); verr != nil {
|
||||||
return nil, verr
|
return nil, verr
|
||||||
}
|
}
|
||||||
|
|
||||||
// try and transform the error to a go-micro error
|
// try and transform the error to a go-micro error
|
||||||
if verr, ok := err.(*errors.Error); ok {
|
if verr, ok := cerr.(*errors.Error); ok {
|
||||||
return nil, verr
|
return nil, verr
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream, err
|
return stream, cerr
|
||||||
}
|
}
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
@@ -506,8 +501,8 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
|
|||||||
|
|
||||||
for i := 0; i <= callOpts.Retries; i++ {
|
for i := 0; i <= callOpts.Retries; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
s, err := call(i)
|
s, cerr := call(i)
|
||||||
ch <- response{s, err}
|
ch <- response{s, cerr}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@@ -5,9 +5,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type httpMessage struct {
|
type httpMessage struct {
|
||||||
|
payload interface{}
|
||||||
topic string
|
topic string
|
||||||
contentType string
|
contentType string
|
||||||
payload interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHTTPMessage(topic string, payload interface{}, contentType string, opts ...client.MessageOption) client.Message {
|
func newHTTPMessage(topic string, payload interface{}, contentType string, opts ...client.MessageOption) client.Message {
|
||||||
|
13
options.go
13
options.go
@@ -26,27 +26,28 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type poolMaxStreams struct{}
|
type poolMaxStreams struct{}
|
||||||
type poolMaxIdle struct{}
|
|
||||||
type codecsKey struct{}
|
|
||||||
type tlsAuth struct{}
|
|
||||||
type maxRecvMsgSizeKey struct{}
|
|
||||||
type maxSendMsgSizeKey struct{}
|
|
||||||
|
|
||||||
// PoolMaxStreams maximum streams on a connectioin
|
// PoolMaxStreams maximum streams on a connectioin
|
||||||
func PoolMaxStreams(n int) client.Option {
|
func PoolMaxStreams(n int) client.Option {
|
||||||
return client.SetOption(poolMaxStreams{}, n)
|
return client.SetOption(poolMaxStreams{}, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type poolMaxIdle struct{}
|
||||||
|
|
||||||
// PoolMaxIdle maximum idle conns of a pool
|
// PoolMaxIdle maximum idle conns of a pool
|
||||||
func PoolMaxIdle(d int) client.Option {
|
func PoolMaxIdle(d int) client.Option {
|
||||||
return client.SetOption(poolMaxIdle{}, d)
|
return client.SetOption(poolMaxIdle{}, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type maxRecvMsgSizeKey struct{}
|
||||||
|
|
||||||
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
||||||
func MaxRecvMsgSize(s int) client.Option {
|
func MaxRecvMsgSize(s int) client.Option {
|
||||||
return client.SetOption(maxRecvMsgSizeKey{}, s)
|
return client.SetOption(maxRecvMsgSizeKey{}, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type maxSendMsgSizeKey struct{}
|
||||||
|
|
||||||
// MaxSendMsgSize set the maximum size of message that client can send.
|
// MaxSendMsgSize set the maximum size of message that client can send.
|
||||||
func MaxSendMsgSize(s int) client.Option {
|
func MaxSendMsgSize(s int) client.Option {
|
||||||
return client.SetOption(maxSendMsgSizeKey{}, s)
|
return client.SetOption(maxSendMsgSizeKey{}, s)
|
||||||
@@ -54,12 +55,14 @@ func MaxSendMsgSize(s int) client.Option {
|
|||||||
|
|
||||||
type httpClientKey struct{}
|
type httpClientKey struct{}
|
||||||
|
|
||||||
|
// nolint: golint
|
||||||
func HTTPClient(c *http.Client) client.Option {
|
func HTTPClient(c *http.Client) client.Option {
|
||||||
return client.SetOption(httpClientKey{}, c)
|
return client.SetOption(httpClientKey{}, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpDialerKey struct{}
|
type httpDialerKey struct{}
|
||||||
|
|
||||||
|
// nolint: golint
|
||||||
func HTTPDialer(d *net.Dialer) client.Option {
|
func HTTPDialer(d *net.Dialer) client.Option {
|
||||||
return client.SetOption(httpDialerKey{}, d)
|
return client.SetOption(httpDialerKey{}, d)
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@ type httpRequest struct {
|
|||||||
|
|
||||||
func newHTTPRequest(service, method string, request interface{}, contentType string, opts ...client.RequestOption) client.Request {
|
func newHTTPRequest(service, method string, request interface{}, contentType string, opts ...client.RequestOption) client.Request {
|
||||||
options := client.NewRequestOptions(opts...)
|
options := client.NewRequestOptions(opts...)
|
||||||
|
|
||||||
if len(options.ContentType) == 0 {
|
if len(options.ContentType) == 0 {
|
||||||
options.ContentType = contentType
|
options.ContentType = contentType
|
||||||
}
|
}
|
||||||
|
67
stream.go
67
stream.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -15,24 +16,21 @@ import (
|
|||||||
|
|
||||||
// Implements the streamer interface
|
// Implements the streamer interface
|
||||||
type httpStream struct {
|
type httpStream struct {
|
||||||
sync.RWMutex
|
|
||||||
address string
|
|
||||||
opts client.CallOptions
|
|
||||||
ct string
|
|
||||||
cf codec.Codec
|
|
||||||
context context.Context
|
|
||||||
header http.Header
|
|
||||||
seq uint64
|
|
||||||
closed chan bool
|
|
||||||
err error
|
err error
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
reader *bufio.Reader
|
cf codec.Codec
|
||||||
|
context context.Context
|
||||||
request client.Request
|
request client.Request
|
||||||
|
header http.Header
|
||||||
|
closed chan bool
|
||||||
|
reader *bufio.Reader
|
||||||
|
address string
|
||||||
|
ct string
|
||||||
|
opts client.CallOptions
|
||||||
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var errShutdown = fmt.Errorf("connection is shut down")
|
||||||
errShutdown = fmt.Errorf("connection is shut down")
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h *httpStream) isClosed() bool {
|
func (h *httpStream) isClosed() bool {
|
||||||
select {
|
select {
|
||||||
@@ -89,7 +87,7 @@ func (h *httpStream) Recv(msg interface{}) error {
|
|||||||
}
|
}
|
||||||
defer hrsp.Body.Close()
|
defer hrsp.Body.Close()
|
||||||
|
|
||||||
return parseRsp(h.context, hrsp, h.cf, msg, h.opts)
|
return h.parseRsp(h.context, hrsp, h.cf, msg, h.opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpStream) Error() error {
|
func (h *httpStream) Error() error {
|
||||||
@@ -107,3 +105,44 @@ func (h *httpStream) Close() error {
|
|||||||
return h.conn.Close()
|
return h.conn.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *httpStream) parseRsp(ctx context.Context, hrsp *http.Response, cf codec.Codec, rsp interface{}, opts client.CallOptions) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
err = ctx.Err()
|
||||||
|
default:
|
||||||
|
// fast path return
|
||||||
|
if hrsp.StatusCode == http.StatusNoContent {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if hrsp.StatusCode < 400 {
|
||||||
|
if err = cf.ReadBody(hrsp.Body, rsp); err != nil {
|
||||||
|
return errors.InternalServerError("go.micro.client", err.Error())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
errmap, ok := opts.Context.Value(errorMapKey{}).(map[string]interface{})
|
||||||
|
if ok && errmap != nil {
|
||||||
|
if err, ok = errmap[fmt.Sprintf("%d", hrsp.StatusCode)].(error); !ok {
|
||||||
|
err, ok = errmap["default"].(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !ok || err == nil {
|
||||||
|
buf, cerr := io.ReadAll(hrsp.Body)
|
||||||
|
if cerr != nil {
|
||||||
|
return errors.InternalServerError("go.micro.client", cerr.Error())
|
||||||
|
}
|
||||||
|
return errors.New("go.micro.client", string(buf), int32(hrsp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cerr := cf.ReadBody(hrsp.Body, err); cerr != nil {
|
||||||
|
err = errors.InternalServerError("go.micro.client", cerr.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
127
util.go
127
util.go
@@ -3,14 +3,14 @@ package http
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"github.com/unistack-org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"github.com/unistack-org/micro/v3/errors"
|
||||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||||
util "github.com/unistack-org/micro/v3/util/router"
|
util "github.com/unistack-org/micro/v3/util/router"
|
||||||
@@ -32,6 +32,7 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
return "", nil, fmt.Errorf("nil message but path params requested: %v", path)
|
return "", nil, fmt.Errorf("nil message but path params requested: %v", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldsmapskip := make(map[string]struct{})
|
||||||
fieldsmap := make(map[string]string, len(tpl.Fields))
|
fieldsmap := make(map[string]string, len(tpl.Fields))
|
||||||
for _, v := range tpl.Fields {
|
for _, v := range tpl.Fields {
|
||||||
fieldsmap[v] = ""
|
fieldsmap[v] = ""
|
||||||
@@ -53,7 +54,7 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
tnmsg = tnmsg.Elem()
|
tnmsg = tnmsg.Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
values := make(map[string]string)
|
values := url.Values{}
|
||||||
// copy cycle
|
// copy cycle
|
||||||
for i := 0; i < tmsg.NumField(); i++ {
|
for i := 0; i < tmsg.NumField(); i++ {
|
||||||
val := tmsg.Field(i)
|
val := tmsg.Field(i)
|
||||||
@@ -73,9 +74,13 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
// special
|
// special
|
||||||
switch tn {
|
switch tn {
|
||||||
case "protobuf": // special
|
case "protobuf": // special
|
||||||
t = &tag{key: tn, name: tp[3][5:], opts: append(tp[:3], tp[4:]...)}
|
for _, p := range tp {
|
||||||
|
if idx := strings.Index(p, "name="); idx > 0 {
|
||||||
|
t = &tag{key: tn, name: p[idx:]}
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
t = &tag{key: tn, name: tp[0], opts: tp[1:]}
|
t = &tag{key: tn, name: tp[0]}
|
||||||
}
|
}
|
||||||
if t.name != "" {
|
if t.name != "" {
|
||||||
break
|
break
|
||||||
@@ -87,18 +92,38 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
t.name = strings.ToLower(fld.Name)
|
t.name = strings.ToLower(fld.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !val.IsValid() || val.IsZero() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// nolint: gocritic
|
||||||
if _, ok := fieldsmap[t.name]; ok {
|
if _, ok := fieldsmap[t.name]; ok {
|
||||||
fieldsmap[t.name] = fmt.Sprintf("%v", val.Interface())
|
switch val.Type().Kind() {
|
||||||
|
case reflect.Slice:
|
||||||
|
for idx := 0; idx < val.Len(); idx++ {
|
||||||
|
values.Add(t.name, fmt.Sprintf("%v", val.Index(idx).Interface()))
|
||||||
|
}
|
||||||
|
fieldsmapskip[t.name] = struct{}{}
|
||||||
|
default:
|
||||||
|
fieldsmap[t.name] = fmt.Sprintf("%v", val.Interface())
|
||||||
|
}
|
||||||
} else if (body == "*" || body == t.name) && method != http.MethodGet {
|
} else if (body == "*" || body == t.name) && method != http.MethodGet {
|
||||||
tnmsg.Field(i).Set(val)
|
tnmsg.Field(i).Set(val)
|
||||||
} else {
|
} else {
|
||||||
values[t.name] = fmt.Sprintf("%v", val.Interface())
|
if val.Type().Kind() == reflect.Slice {
|
||||||
|
for idx := 0; idx < val.Len(); idx++ {
|
||||||
|
values.Add(t.name, fmt.Sprintf("%v", val.Index(idx).Interface()))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
values.Add(t.name, fmt.Sprintf("%v", val.Interface()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check not filled stuff
|
// check not filled stuff
|
||||||
for k, v := range fieldsmap {
|
for k, v := range fieldsmap {
|
||||||
if v == "" {
|
_, ok := fieldsmapskip[k]
|
||||||
|
if !ok && v == "" {
|
||||||
return "", nil, fmt.Errorf("path param %s not filled", k)
|
return "", nil, fmt.Errorf("path param %s not filled", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,23 +132,17 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
for _, fld := range tpl.Pool {
|
for _, fld := range tpl.Pool {
|
||||||
_, _ = b.WriteRune('/')
|
_, _ = b.WriteRune('/')
|
||||||
if v, ok := fieldsmap[fld]; ok {
|
if v, ok := fieldsmap[fld]; ok {
|
||||||
_, _ = b.WriteString(v)
|
if v != "" {
|
||||||
|
_, _ = b.WriteString(v)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_, _ = b.WriteString(fld)
|
_, _ = b.WriteString(fld)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idx := 0
|
if len(values) > 0 {
|
||||||
for k, v := range values {
|
_, _ = b.WriteRune('?')
|
||||||
if idx == 0 {
|
_, _ = b.WriteString(values.Encode())
|
||||||
_, _ = b.WriteRune('?')
|
|
||||||
} else {
|
|
||||||
_, _ = b.WriteRune('&')
|
|
||||||
}
|
|
||||||
_, _ = b.WriteString(k)
|
|
||||||
_, _ = b.WriteRune('=')
|
|
||||||
_, _ = b.WriteString(v)
|
|
||||||
idx++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rutil.IsZero(nmsg) {
|
if rutil.IsZero(nmsg) {
|
||||||
@@ -155,36 +174,53 @@ func newTemplate(path string) (util.Template, error) {
|
|||||||
return tpl, nil
|
return tpl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRsp(ctx context.Context, hrsp *http.Response, cf codec.Codec, rsp interface{}, opts client.CallOptions) error {
|
func (h *httpClient) parseRsp(ctx context.Context, hrsp *http.Response, rsp interface{}, opts client.CallOptions) error {
|
||||||
b, err := ioutil.ReadAll(hrsp.Body)
|
var err error
|
||||||
if err != nil {
|
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if hrsp.StatusCode < 400 {
|
select {
|
||||||
// unmarshal
|
case <-ctx.Done():
|
||||||
if err := cf.Unmarshal(b, rsp); err != nil {
|
err = ctx.Err()
|
||||||
return errors.InternalServerError("go.micro.client", err.Error())
|
default:
|
||||||
|
// fast path return
|
||||||
|
if hrsp.StatusCode == http.StatusNoContent {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
errmap, ok := opts.Context.Value(errorMapKey{}).(map[string]interface{})
|
ct := DefaultContentType
|
||||||
if !ok || errmap == nil {
|
|
||||||
// user not provide map of errors
|
|
||||||
// id: req.Service() ??
|
|
||||||
return errors.New("go.micro.client", string(b), int32(hrsp.StatusCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err, ok = errmap[fmt.Sprintf("%d", hrsp.StatusCode)].(error); !ok {
|
if htype := hrsp.Header.Get("Content-Type"); htype != "" {
|
||||||
err, ok = errmap["default"].(error)
|
ct = htype
|
||||||
}
|
}
|
||||||
if !ok {
|
|
||||||
return errors.New("go.micro.client", string(b), int32(hrsp.StatusCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
if cerr := cf.Unmarshal(b, err); cerr != nil {
|
cf, cerr := h.newCodec(ct)
|
||||||
return errors.InternalServerError("go.micro.client", cerr.Error())
|
if cerr != nil {
|
||||||
|
return errors.InternalServerError("go.micro.client", cerr.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if hrsp.StatusCode < 400 {
|
||||||
|
if err = cf.ReadBody(hrsp.Body, rsp); err != nil {
|
||||||
|
return errors.InternalServerError("go.micro.client", err.Error())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
errmap, ok := opts.Context.Value(errorMapKey{}).(map[string]interface{})
|
||||||
|
if ok && errmap != nil {
|
||||||
|
if err, ok = errmap[fmt.Sprintf("%d", hrsp.StatusCode)].(error); !ok {
|
||||||
|
err, ok = errmap["default"].(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !ok || err == nil {
|
||||||
|
buf, rerr := io.ReadAll(hrsp.Body)
|
||||||
|
if rerr != nil {
|
||||||
|
return errors.InternalServerError("go.micro.client", rerr.Error())
|
||||||
|
}
|
||||||
|
return errors.New("go.micro.client", string(buf), int32(hrsp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
|
if cerr := cf.ReadBody(hrsp.Body, err); cerr != nil {
|
||||||
|
err = errors.InternalServerError("go.micro.client", cerr.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@@ -193,5 +229,4 @@ func parseRsp(ctx context.Context, hrsp *http.Response, cf codec.Codec, rsp inte
|
|||||||
type tag struct {
|
type tag struct {
|
||||||
key string
|
key string
|
||||||
name string
|
name string
|
||||||
opts []string
|
|
||||||
}
|
}
|
||||||
|
@@ -18,8 +18,8 @@ func TestNewPathRequest(t *testing.T) {
|
|||||||
type Message struct {
|
type Message struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Val1 string `protobuf:"bytes,1,opt,name=val1,proto3" json:"val1"`
|
Val1 string `protobuf:"bytes,1,opt,name=val1,proto3" json:"val1"`
|
||||||
Val2 int64
|
|
||||||
Val3 []string
|
Val3 []string
|
||||||
|
Val2 int64
|
||||||
}
|
}
|
||||||
|
|
||||||
omsg := &Message{Name: "test_name", Val1: "test_val1", Val2: 100, Val3: []string{"slice"}}
|
omsg := &Message{Name: "test_name", Val1: "test_val1", Val2: 100, Val3: []string{"slice"}}
|
||||||
@@ -45,8 +45,8 @@ func TestNewPathVarRequest(t *testing.T) {
|
|||||||
type Message struct {
|
type Message struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Val1 string `protobuf:"bytes,1,opt,name=val1,proto3" json:"val1"`
|
Val1 string `protobuf:"bytes,1,opt,name=val1,proto3" json:"val1"`
|
||||||
Val2 int64
|
|
||||||
Val3 []string
|
Val3 []string
|
||||||
|
Val2 int64
|
||||||
}
|
}
|
||||||
|
|
||||||
omsg := &Message{Name: "test_name", Val1: "test_val1", Val2: 100, Val3: []string{"slice"}}
|
omsg := &Message{Name: "test_name", Val1: "test_val1", Val2: 100, Val3: []string{"slice"}}
|
||||||
|
Reference in New Issue
Block a user