update metadata

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-11-18 13:02:53 +03:00
parent b12d45f45c
commit 156c93b8fa
5 changed files with 26 additions and 29 deletions

2
go.mod
View File

@ -5,6 +5,6 @@ go 1.13
require ( require (
github.com/unistack-org/micro-codec-jsonrpc v0.0.0-20201102222451-ff6a69988bcd github.com/unistack-org/micro-codec-jsonrpc v0.0.0-20201102222451-ff6a69988bcd
github.com/unistack-org/micro-codec-protorpc v0.0.0-20201102222610-3a343898c077 github.com/unistack-org/micro-codec-protorpc v0.0.0-20201102222610-3a343898c077
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201104214903-1fbf8b2e209e github.com/unistack-org/micro/v3 v3.0.2-0.20201117210202-01e64cb0c0f3
golang.org/x/net v0.0.0-20200904194848-62affa334b73 golang.org/x/net v0.0.0-20200904194848-62affa334b73
) )

2
go.sum
View File

@ -307,6 +307,8 @@ github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920135754-1cbd1d2bad83/go.m
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922103357-4c4fa00a5d94/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922103357-4c4fa00a5d94/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201104214903-1fbf8b2e209e h1:v27OUgoE2UOyCe6uLksdpG6oErx62nUXWIkTPxS7yIw= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201104214903-1fbf8b2e209e h1:v27OUgoE2UOyCe6uLksdpG6oErx62nUXWIkTPxS7yIw=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201104214903-1fbf8b2e209e/go.mod h1:LFvCXGOgcLIj2k/8eL71TpIpcJBN2SXXAUx8U6dz9Rw= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201104214903-1fbf8b2e209e/go.mod h1:LFvCXGOgcLIj2k/8eL71TpIpcJBN2SXXAUx8U6dz9Rw=
github.com/unistack-org/micro/v3 v3.0.2-0.20201117210202-01e64cb0c0f3 h1:knz0mt3Ot/CIXp5dRyb5dAPYtKiWA9PDhazpXX5Iu3o=
github.com/unistack-org/micro/v3 v3.0.2-0.20201117210202-01e64cb0c0f3/go.mod h1:LYbzHigEudM10AbLZztVSX0Y4JWgj5nKIExil/99h6E=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

View File

@ -1,12 +1,15 @@
package tcp package tcp
import "github.com/unistack-org/micro/v3/codec" import (
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/metadata"
)
type tcpMessage struct { type tcpMessage struct {
topic string topic string
payload interface{} payload interface{}
contentType string contentType string
header map[string]string header metadata.Metadata
body []byte body []byte
codec codec.Reader codec codec.Reader
} }
@ -23,7 +26,7 @@ func (r *tcpMessage) ContentType() string {
return r.contentType return r.contentType
} }
func (r *tcpMessage) Header() map[string]string { func (r *tcpMessage) Header() metadata.Metadata {
return r.header return r.header
} }

View File

@ -80,15 +80,14 @@ func newSubscriber(topic string, sub interface{}, opts ...server.SubscriberOptio
} }
handlers = append(handlers, h) handlers = append(handlers, h)
ep := &registry.Endpoint{
endpoints = append(endpoints, &registry.Endpoint{ Name: "Func",
Name: "Func", Request: registry.ExtractSubValue(typ),
Request: registry.ExtractSubValue(typ), Metadata: metadata.New(2),
Metadata: map[string]string{ }
"topic": topic, ep.Metadata.Set("topic", topic)
"subscriber": "true", ep.Metadata.Set("subscriber", "true")
}, endpoints = append(endpoints, ep)
})
} else { } else {
hdlr := reflect.ValueOf(sub) hdlr := reflect.ValueOf(sub)
name := reflect.Indirect(hdlr).Type().Name() name := reflect.Indirect(hdlr).Type().Name()
@ -108,15 +107,14 @@ func newSubscriber(topic string, sub interface{}, opts ...server.SubscriberOptio
} }
handlers = append(handlers, h) handlers = append(handlers, h)
ep := &registry.Endpoint{
endpoints = append(endpoints, &registry.Endpoint{ Name: name + "." + method.Name,
Name: name + "." + method.Name, Request: registry.ExtractSubValue(method.Type),
Request: registry.ExtractSubValue(method.Type), Metadata: metadata.New(2),
Metadata: map[string]string{ }
"topic": topic, ep.Metadata.Set("topic", topic)
"subscriber": "true", ep.Metadata.Set("subscriber", "true")
}, endpoints = append(endpoints, ep)
})
} }
} }

8
tcp.go
View File

@ -75,13 +75,7 @@ func (h *tcpServer) Handle(handler server.Handler) error {
} }
func (h *tcpServer) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler { func (h *tcpServer) NewHandler(handler interface{}, opts ...server.HandlerOption) server.Handler {
options := server.HandlerOptions{ options := server.NewHandlerOptions(opts...)
Metadata: make(map[string]map[string]string),
}
for _, o := range opts {
o(&options)
}
var eps []*registry.Endpoint var eps []*registry.Endpoint