forked from openzipkin-contrib/zipkin-go-opentracing
/
implementation.go
50 lines (39 loc) · 1.14 KB
/
implementation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build go1.7
package svc1
import (
"context"
opentracing "github.com/opentracing/opentracing-go"
"github.com/openzipkin/zipkin-go-opentracing/examples/cli_with_2_services/svc2"
)
// svc1 is our actual service implementation
type svc1 struct {
svc2Client svc2.Service
}
func (s *svc1) Concat(ctx context.Context, a, b string) (string, error) {
// test for length overflow
if len(a)+len(b) > StrMaxSize {
// pull span from context (has already been created by our middleware)
span := opentracing.SpanFromContext(ctx)
span.SetTag("error", ErrMaxSize.Error())
return "", ErrMaxSize
}
return a + b, nil
}
func (s *svc1) Sum(ctx context.Context, a, b int64) (int64, error) {
// pull span from context (has already been created by our middleware)
span := opentracing.SpanFromContext(ctx)
span.SetTag("proxy-to", "svc2")
// proxy request to svc2
result, err := s.svc2Client.Sum(ctx, a, b)
if err != nil {
span.SetTag("error", err.Error())
return 0, err
}
return result, nil
}
// NewService returns a new implementation of our Service.
func NewService(svc2Client svc2.Service) Service {
return &svc1{
svc2Client: svc2Client,
}
}