use metadata.Metadata (#8)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/unistack-org/micro/v3/broker"
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
"github.com/unistack-org/micro/v3/registry"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
@@ -24,7 +25,7 @@ type Options struct {
|
||||
Auth auth.Auth
|
||||
Logger logger.Logger
|
||||
Transport transport.Transport
|
||||
Metadata map[string]string
|
||||
Metadata metadata.Metadata
|
||||
Name string
|
||||
Address string
|
||||
Advertise string
|
||||
@@ -63,7 +64,7 @@ func NewOptions(opts ...Option) Options {
|
||||
Auth: auth.DefaultAuth,
|
||||
Codecs: make(map[string]codec.NewCodec),
|
||||
Context: context.Background(),
|
||||
Metadata: map[string]string{},
|
||||
Metadata: metadata.New(0),
|
||||
RegisterInterval: DefaultRegisterInterval,
|
||||
RegisterTTL: DefaultRegisterTTL,
|
||||
RegisterCheck: DefaultRegisterCheck,
|
||||
@@ -187,9 +188,9 @@ func Transport(t transport.Transport) Option {
|
||||
}
|
||||
|
||||
// Metadata associated with the server
|
||||
func Metadata(md map[string]string) Option {
|
||||
func Metadata(md metadata.Metadata) Option {
|
||||
return func(o *Options) {
|
||||
o.Metadata = md
|
||||
o.Metadata = metadata.Copy(md)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +272,7 @@ type HandlerOption func(*HandlerOptions)
|
||||
// HandlerOptions struct
|
||||
type HandlerOptions struct {
|
||||
Internal bool
|
||||
Metadata map[string]map[string]string
|
||||
Metadata map[string]metadata.Metadata
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
@@ -317,9 +318,9 @@ func NewSubscriberOptions(opts ...SubscriberOption) SubscriberOptions {
|
||||
|
||||
// EndpointMetadata is a Handler option that allows metadata to be added to
|
||||
// individual endpoints.
|
||||
func EndpointMetadata(name string, md map[string]string) HandlerOption {
|
||||
func EndpointMetadata(name string, md metadata.Metadata) HandlerOption {
|
||||
return func(o *HandlerOptions) {
|
||||
o.Metadata[name] = md
|
||||
o.Metadata[name] = metadata.Copy(md)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,13 +2,14 @@ package server
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
type rpcMessage struct {
|
||||
topic string
|
||||
contentType string
|
||||
payload interface{}
|
||||
header map[string]string
|
||||
header metadata.Metadata
|
||||
body []byte
|
||||
codec codec.Codec
|
||||
}
|
||||
@@ -25,7 +26,7 @@ func (r *rpcMessage) Payload() interface{} {
|
||||
return r.payload
|
||||
}
|
||||
|
||||
func (r *rpcMessage) Header() map[string]string {
|
||||
func (r *rpcMessage) Header() metadata.Metadata {
|
||||
return r.header
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/unistack-org/micro/v3/codec"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
"github.com/unistack-org/micro/v3/registry"
|
||||
)
|
||||
|
||||
@@ -53,7 +54,7 @@ type Message interface {
|
||||
// The content type of the payload
|
||||
ContentType() string
|
||||
// The raw headers of the message
|
||||
Header() map[string]string
|
||||
Header() metadata.Metadata
|
||||
// The raw body of the message
|
||||
Body() []byte
|
||||
// Codec used to decode the message
|
||||
@@ -71,7 +72,7 @@ type Request interface {
|
||||
// Content type provided
|
||||
ContentType() string
|
||||
// Header of the request
|
||||
Header() map[string]string
|
||||
Header() metadata.Metadata
|
||||
// Body is the initial decoded value
|
||||
Body() interface{}
|
||||
// Read the undecoded request body
|
||||
@@ -87,7 +88,7 @@ type Response interface {
|
||||
// Encoded writer
|
||||
Codec() codec.Writer
|
||||
// Write the header
|
||||
WriteHeader(map[string]string)
|
||||
WriteHeader(metadata.Metadata)
|
||||
// write a response directly to the client
|
||||
Write([]byte) error
|
||||
}
|
||||
|
@@ -134,15 +134,14 @@ func newSubscriber(topic string, sub interface{}, opts ...SubscriberOption) Subs
|
||||
}
|
||||
|
||||
handlers = append(handlers, h)
|
||||
|
||||
endpoints = append(endpoints, ®istry.Endpoint{
|
||||
Name: "Func",
|
||||
Request: registry.ExtractSubValue(typ),
|
||||
Metadata: map[string]string{
|
||||
"topic": topic,
|
||||
"subscriber": "true",
|
||||
},
|
||||
})
|
||||
ep := ®istry.Endpoint{
|
||||
Name: "Func",
|
||||
Request: registry.ExtractSubValue(typ),
|
||||
Metadata: metadata.New(2),
|
||||
}
|
||||
ep.Metadata.Set("topic", topic)
|
||||
ep.Metadata.Set("subscriber", "true")
|
||||
endpoints = append(endpoints, ep)
|
||||
} else {
|
||||
hdlr := reflect.ValueOf(sub)
|
||||
name := reflect.Indirect(hdlr).Type().Name()
|
||||
@@ -162,15 +161,14 @@ func newSubscriber(topic string, sub interface{}, opts ...SubscriberOption) Subs
|
||||
}
|
||||
|
||||
handlers = append(handlers, h)
|
||||
|
||||
endpoints = append(endpoints, ®istry.Endpoint{
|
||||
Name: name + "." + method.Name,
|
||||
Request: registry.ExtractSubValue(method.Type),
|
||||
Metadata: map[string]string{
|
||||
"topic": topic,
|
||||
"subscriber": "true",
|
||||
},
|
||||
})
|
||||
ep := ®istry.Endpoint{
|
||||
Name: name + "." + method.Name,
|
||||
Request: registry.ExtractSubValue(method.Type),
|
||||
Metadata: metadata.New(2),
|
||||
}
|
||||
ep.Metadata.Set("topic", topic)
|
||||
ep.Metadata.Set("subscriber", "true")
|
||||
endpoints = append(endpoints, ep)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user