Change initialisation and add metadata
This commit is contained in:
@@ -19,7 +19,7 @@ func main() {
|
||||
})
|
||||
|
||||
// create context with metadata
|
||||
ctx := c.WithMetaData(context.Background(), map[string]string{
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
"X-User-Id": "john",
|
||||
"X-From-Id": "script",
|
||||
})
|
||||
|
@@ -20,7 +20,7 @@ func pub() {
|
||||
tick := time.NewTicker(time.Second)
|
||||
i := 0
|
||||
for _ = range tick.C {
|
||||
ctx := c.WithMetaData(context.Background(), map[string]string{
|
||||
ctx := c.WithMetadata(context.Background(), map[string]string{
|
||||
"id": fmt.Sprintf("%d", i),
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ func pub() {
|
||||
|
||||
func sub() {
|
||||
_, err := broker.Subscribe(topic, func(ctx context.Context, msg *broker.Message) {
|
||||
md, _ := c.GetMetaData(ctx)
|
||||
md, _ := c.GetMetadata(ctx)
|
||||
fmt.Println("[sub] received message:", string(msg.Body), "context", md)
|
||||
})
|
||||
if err != nil {
|
||||
|
@@ -12,8 +12,8 @@ import (
|
||||
type Example struct{}
|
||||
|
||||
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
|
||||
md, _ := c.GetMetaData(ctx)
|
||||
md, _ := c.GetMetadata(ctx)
|
||||
log.Info("Received Example.Call request with metadata: %v", md)
|
||||
rsp.Msg = server.Id + ": Hello " + req.Name
|
||||
rsp.Msg = server.Config().Id() + ": Hello " + req.Name
|
||||
return nil
|
||||
}
|
||||
|
@@ -11,10 +11,10 @@ func main() {
|
||||
// optionally setup command line usage
|
||||
cmd.Init()
|
||||
|
||||
server.Name = "go.micro.srv.example"
|
||||
|
||||
// Initialise Server
|
||||
server.Init()
|
||||
server.Init(
|
||||
server.Name("go.micro.srv.example"),
|
||||
)
|
||||
|
||||
// Register Handlers
|
||||
server.Register(
|
||||
|
Reference in New Issue
Block a user