Move context to metadata
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
c "github.com/micro/go-micro/context"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"github.com/micro/go-micro/registry"
|
||||
"github.com/micro/go-micro/selector"
|
||||
"golang.org/x/net/context"
|
||||
@@ -25,7 +25,7 @@ type dcWrapper struct {
|
||||
}
|
||||
|
||||
func (dc *dcWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
md, _ := c.GetMetadata(ctx)
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
|
||||
filter := func(services []*registry.Service) []*registry.Service {
|
||||
for _, service := range services {
|
||||
@@ -59,7 +59,7 @@ func call(i int) {
|
||||
})
|
||||
|
||||
// create context with metadata
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
ctx := metadata.NewContext(context.Background(), map[string]string{
|
||||
"datacenter": "local",
|
||||
})
|
||||
|
||||
|
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
c "github.com/micro/go-micro/context"
|
||||
example "github.com/micro/go-micro/examples/server/proto/example"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ func pub() {
|
||||
})
|
||||
|
||||
// create context with metadata
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
ctx := metadata.NewContext(context.Background(), map[string]string{
|
||||
"X-User-Id": "john",
|
||||
"X-From-Id": "script",
|
||||
})
|
||||
@@ -38,7 +38,7 @@ func call(i int) {
|
||||
})
|
||||
|
||||
// create context with metadata
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
ctx := metadata.NewContext(context.Background(), map[string]string{
|
||||
"X-User-Id": "john",
|
||||
"X-From-Id": "script",
|
||||
})
|
||||
|
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
c "github.com/micro/go-micro/context"
|
||||
example "github.com/micro/go-micro/examples/server/proto/example"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ func pub(i int) {
|
||||
})
|
||||
|
||||
// create context with metadata
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
ctx := metadata.NewContext(context.Background(), map[string]string{
|
||||
"X-User-Id": "john",
|
||||
"X-From-Id": "script",
|
||||
})
|
||||
|
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/cmd"
|
||||
c "github.com/micro/go-micro/context"
|
||||
example "github.com/micro/go-micro/examples/server/proto/example"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ type logWrapper struct {
|
||||
}
|
||||
|
||||
func (l *logWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
md, _ := c.GetMetadata(ctx)
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
fmt.Printf("[Log Wrapper] ctx: %v service: %s method: %s\n", md, req.Service(), req.Method())
|
||||
return l.Client.Call(ctx, req, rsp)
|
||||
}
|
||||
@@ -30,7 +30,7 @@ type traceWrapper struct {
|
||||
}
|
||||
|
||||
func (t *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
ctx = c.WithMetadata(ctx, map[string]string{
|
||||
ctx = metadata.NewContext(ctx, map[string]string{
|
||||
"X-Trace-Id": fmt.Sprintf("%d", time.Now().Unix()),
|
||||
})
|
||||
return t.Client.Call(ctx, req, rsp)
|
||||
@@ -53,7 +53,7 @@ func call(i int) {
|
||||
})
|
||||
|
||||
// create context with metadata
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
ctx := metadata.NewContext(context.Background(), map[string]string{
|
||||
"X-User-Id": "john",
|
||||
"X-From-Id": "script",
|
||||
})
|
||||
|
@@ -2,8 +2,8 @@ package handler
|
||||
|
||||
import (
|
||||
log "github.com/golang/glog"
|
||||
c "github.com/micro/go-micro/context"
|
||||
example "github.com/micro/go-micro/examples/server/proto/example"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"github.com/micro/go-micro/server"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
type Example struct{}
|
||||
|
||||
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
|
||||
md, _ := c.GetMetadata(ctx)
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
log.Infof("Received Example.Call request with metadata: %v", md)
|
||||
rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name
|
||||
return nil
|
||||
|
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/micro/cli"
|
||||
"github.com/micro/go-micro"
|
||||
"github.com/micro/go-micro/client"
|
||||
c "github.com/micro/go-micro/context"
|
||||
proto "github.com/micro/go-micro/examples/service/proto"
|
||||
"github.com/micro/go-micro/metadata"
|
||||
"github.com/micro/go-micro/server"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@@ -24,7 +24,7 @@ type logWrapper struct {
|
||||
}
|
||||
|
||||
func (l *logWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
md, _ := c.GetMetadata(ctx)
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
fmt.Printf("[Log Wrapper] ctx: %v service: %s method: %s\n", md, req.Service(), req.Method())
|
||||
return l.Client.Call(ctx, req, rsp)
|
||||
}
|
||||
|
Reference in New Issue
Block a user