Skip to content

Commit

Permalink
Fix the breaking build
Browse files Browse the repository at this point in the history
  • Loading branch information
Asim committed Nov 26, 2015
1 parent fb172df commit dc5f121
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 87 deletions.
56 changes: 56 additions & 0 deletions examples/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

"github.com/micro/go-micro/client"
"github.com/micro/go-micro/cmd"
Expand All @@ -10,6 +11,42 @@ import (
"golang.org/x/net/context"
)

// wrapper example code

// log wrapper logs every time a request is made
type logWrapper struct {
client.Client
}

func (l *logWrapper) Call(ctx context.Context, req client.Request, rsp interface{}) error {
md, _ := c.GetMetadata(ctx)
fmt.Printf("[Log Wrapper] ctx: %v service: %s method: %s\n", md, req.Service(), req.Method())
return l.Client.Call(ctx, req, rsp)
}

// trace wrapper attaches a unique trace ID - timestamp
type traceWrapper struct {
client.Client
}

func (t *traceWrapper) Call(ctx context.Context, req client.Request, rsp interface{}) error {
ctx = c.WithMetadata(ctx, map[string]string{
"X-Trace-Id": fmt.Sprintf("%d", time.Now().Unix()),
})
return t.Client.Call(ctx, req, rsp)
}

// Implements client.Wrapper as logWrapper
func logWrap(c client.Client) client.Client {
return &logWrapper{c}
}

// Implements client.Wrapper as traceWrapper
func traceWrap(c client.Client) client.Client {
return &traceWrapper{c}
}

// publishes a message
func pub() {
msg := client.NewPublication("topic.go.micro.srv.example", &example.Message{
Say: "This is a publication",
Expand Down Expand Up @@ -82,10 +119,29 @@ func stream() {
func main() {
cmd.Init()

fmt.Println("\n--- Call example ---\n")
for i := 0; i < 10; i++ {
call(i)
}

fmt.Println("\n--- Streamer example ---\n")
stream()

fmt.Println("\n--- Publisher example ---\n")
pub()

fmt.Println("\n--- Wrapper example ---\n")

// Wrap the default client
client.DefaultClient = logWrap(client.DefaultClient)

call(0)

// Wrap using client.Wrap option
client.DefaultClient = client.NewClient(
client.Wrap(traceWrap),
client.Wrap(logWrap),
)

call(1)
}
87 changes: 0 additions & 87 deletions examples/client/wrapper.go

This file was deleted.

0 comments on commit dc5f121

Please sign in to comment.