Compare commits
4 Commits
v3.11.19
...
98981ba86c
| Author | SHA1 | Date | |
|---|---|---|---|
| 98981ba86c | |||
| 1013f50d0e | |||
| 0b190997b1 | |||
| 69a44eb190 |
@@ -109,7 +109,7 @@ func (m *memoryBroker) Init(opts ...broker.Option) error {
|
|||||||
m.funcSubscribe = m.fnSubscribe
|
m.funcSubscribe = m.fnSubscribe
|
||||||
m.funcBatchSubscribe = m.fnBatchSubscribe
|
m.funcBatchSubscribe = m.fnBatchSubscribe
|
||||||
|
|
||||||
m.opts.Hooks.EachNext(func(hook options.Hook) {
|
m.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
switch h := hook.(type) {
|
switch h := hook.(type) {
|
||||||
case broker.HookPublish:
|
case broker.HookPublish:
|
||||||
m.funcPublish = h(m.funcPublish)
|
m.funcPublish = h(m.funcPublish)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (b *NoopBroker) Init(opts ...Option) error {
|
|||||||
b.funcSubscribe = b.fnSubscribe
|
b.funcSubscribe = b.fnSubscribe
|
||||||
b.funcBatchSubscribe = b.fnBatchSubscribe
|
b.funcBatchSubscribe = b.fnBatchSubscribe
|
||||||
|
|
||||||
b.opts.Hooks.EachNext(func(hook options.Hook) {
|
b.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
switch h := hook.(type) {
|
switch h := hook.(type) {
|
||||||
case HookPublish:
|
case HookPublish:
|
||||||
b.funcPublish = h(b.funcPublish)
|
b.funcPublish = h(b.funcPublish)
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ func (n *noopClient) Init(opts ...Option) error {
|
|||||||
n.funcPublish = n.fnPublish
|
n.funcPublish = n.fnPublish
|
||||||
n.funcBatchPublish = n.fnBatchPublish
|
n.funcBatchPublish = n.fnBatchPublish
|
||||||
|
|
||||||
n.opts.Hooks.EachNext(func(hook options.Hook) {
|
n.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
switch h := hook.(type) {
|
switch h := hook.(type) {
|
||||||
case HookCall:
|
case HookCall:
|
||||||
n.funcCall = h(n.funcCall)
|
n.funcCall = h(n.funcCall)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (c *defaultConfig) Init(opts ...Option) error {
|
|||||||
c.funcLoad = c.fnLoad
|
c.funcLoad = c.fnLoad
|
||||||
c.funcSave = c.fnSave
|
c.funcSave = c.fnSave
|
||||||
|
|
||||||
c.opts.Hooks.EachNext(func(hook options.Hook) {
|
c.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
switch h := hook.(type) {
|
switch h := hook.(type) {
|
||||||
case HookLoad:
|
case HookLoad:
|
||||||
c.funcLoad = h(c.funcLoad)
|
c.funcLoad = h(c.funcLoad)
|
||||||
|
|||||||
@@ -68,15 +68,7 @@ func (md Metadata) Iterator() *Iterator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (md Metadata) MustGet(key string) string {
|
func (md Metadata) MustGet(key string) string {
|
||||||
// fast path
|
val, ok := md.Get(key)
|
||||||
val, ok := md[key]
|
|
||||||
if !ok {
|
|
||||||
// slow path
|
|
||||||
val, ok = md[textproto.CanonicalMIMEHeaderKey(key)]
|
|
||||||
if !ok {
|
|
||||||
val, ok = md[strings.ToLower(key)]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("missing metadata key")
|
panic("missing metadata key")
|
||||||
}
|
}
|
||||||
@@ -119,11 +111,18 @@ func (md Metadata) Del(keys ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy makes a copy of the metadata
|
||||||
|
func (md Metadata) CopyTo(dst Metadata) {
|
||||||
|
for k, v := range md {
|
||||||
|
dst[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Copy makes a copy of the metadata
|
// Copy makes a copy of the metadata
|
||||||
func Copy(md Metadata, exclude ...string) Metadata {
|
func Copy(md Metadata, exclude ...string) Metadata {
|
||||||
nmd := New(len(md))
|
nmd := New(len(md))
|
||||||
for key, val := range md {
|
for k, v := range md {
|
||||||
nmd.Set(key, val)
|
nmd[k] = v
|
||||||
}
|
}
|
||||||
nmd.Del(exclude...)
|
nmd.Del(exclude...)
|
||||||
return nmd
|
return nmd
|
||||||
@@ -147,7 +146,7 @@ func Merge(omd Metadata, mmd Metadata, overwrite bool) Metadata {
|
|||||||
case ok && !overwrite:
|
case ok && !overwrite:
|
||||||
continue
|
continue
|
||||||
case val != "":
|
case val != "":
|
||||||
nmd.Set(key, val)
|
nmd[key] = val
|
||||||
case ok && val == "":
|
case ok && val == "":
|
||||||
nmd.Del(key)
|
nmd.Del(key)
|
||||||
}
|
}
|
||||||
@@ -161,6 +160,8 @@ func Pairs(kv ...string) (Metadata, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
md := New(len(kv) / 2)
|
md := New(len(kv) / 2)
|
||||||
md.Set(kv...)
|
for idx := 0; idx < len(kv); idx += 2 {
|
||||||
|
md[kv[idx]] = kv[idx+1]
|
||||||
|
}
|
||||||
return md, true
|
return md, true
|
||||||
}
|
}
|
||||||
|
|||||||
18
semconv/metadata.go
Normal file
18
semconv/metadata.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package semconv
|
||||||
|
|
||||||
|
var (
|
||||||
|
// HeaderTopic is the header name that contains topic name
|
||||||
|
HeaderTopic = "Micro-Topic"
|
||||||
|
// HeaderContentType specifies content type of message
|
||||||
|
HeaderContentType = "Content-Type"
|
||||||
|
// HeaderEndpoint specifies endpoint in service
|
||||||
|
HeaderEndpoint = "Micro-Endpoint"
|
||||||
|
// HeaderService specifies service
|
||||||
|
HeaderService = "Micro-Service"
|
||||||
|
// HeaderTimeout specifies timeout of operation
|
||||||
|
HeaderTimeout = "Micro-Timeout"
|
||||||
|
// HeaderAuthorization specifies Authorization header
|
||||||
|
HeaderAuthorization = "Authorization"
|
||||||
|
// HeaderXRequestID specifies request id
|
||||||
|
HeaderXRequestID = "X-Request-Id"
|
||||||
|
)
|
||||||
@@ -723,7 +723,7 @@ func (n *noopServer) createSubHandler(sb *subscriber, opts Options) broker.Handl
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Hooks.EachNext(func(hook options.Hook) {
|
opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
if h, ok := hook.(HookSubHandler); ok {
|
if h, ok := hook.(HookSubHandler); ok {
|
||||||
fn = h(fn)
|
fn = h(fn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"go.unistack.org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
|
"go.unistack.org/micro/v3/options"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -84,3 +85,40 @@ func TestNoopSub(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHooks_Wrap(t *testing.T) {
|
||||||
|
n := 5
|
||||||
|
fn1 := func(next server.FuncSubHandler) server.FuncSubHandler {
|
||||||
|
return func(ctx context.Context, msg server.Message) (err error) {
|
||||||
|
n *= 2
|
||||||
|
return next(ctx, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn2 := func(next server.FuncSubHandler) server.FuncSubHandler {
|
||||||
|
return func(ctx context.Context, msg server.Message) (err error) {
|
||||||
|
n -= 10
|
||||||
|
return next(ctx, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hs := &options.Hooks{}
|
||||||
|
hs.Append(server.HookSubHandler(fn1), server.HookSubHandler(fn2))
|
||||||
|
|
||||||
|
var fn = func(ctx context.Context, msg server.Message) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
hs.EachPrev(func(hook options.Hook) {
|
||||||
|
if h, ok := hook.(server.HookSubHandler); ok {
|
||||||
|
fn = h(fn)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := fn(nil, nil); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if n != 0 {
|
||||||
|
t.Fatalf("uncorrected hooks call")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ func (m *memoryStore) Init(opts ...store.Option) error {
|
|||||||
m.funcList = m.fnList
|
m.funcList = m.fnList
|
||||||
m.funcDelete = m.fnDelete
|
m.funcDelete = m.fnDelete
|
||||||
|
|
||||||
m.opts.Hooks.EachNext(func(hook options.Hook) {
|
m.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
switch h := hook.(type) {
|
switch h := hook.(type) {
|
||||||
case store.HookRead:
|
case store.HookRead:
|
||||||
m.funcRead = h(m.funcRead)
|
m.funcRead = h(m.funcRead)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func (n *noopStore) Init(opts ...Option) error {
|
|||||||
n.funcList = n.fnList
|
n.funcList = n.fnList
|
||||||
n.funcDelete = n.fnDelete
|
n.funcDelete = n.fnDelete
|
||||||
|
|
||||||
n.opts.Hooks.EachNext(func(hook options.Hook) {
|
n.opts.Hooks.EachPrev(func(hook options.Hook) {
|
||||||
switch h := hook.(type) {
|
switch h := hook.(type) {
|
||||||
case HookRead:
|
case HookRead:
|
||||||
n.funcRead = h(n.funcRead)
|
n.funcRead = h(n.funcRead)
|
||||||
|
|||||||
Reference in New Issue
Block a user