@@ -30,10 +30,10 @@ type testSpanContext struct {
3030func (n testSpanContext ) ForeachBaggageItem (handler func (k , v string ) bool ) {}
3131
3232type testSpan struct {
33- spanContext testSpanContext
34- OperationName string
3533 StartTime time.Time
3634 Tags map [string ]interface {}
35+ OperationName string
36+ spanContext testSpanContext
3737}
3838
3939func (n testSpan ) Equal (os opentracing.Span ) bool {
@@ -63,7 +63,6 @@ func (n testSpan) Equal(os opentracing.Span) bool {
6363 return true
6464}
6565
66- // testSpan:
6766func (n testSpan ) Context () opentracing.SpanContext { return n .spanContext }
6867func (n testSpan ) SetTag (key string , value interface {}) opentracing.Span { return n }
6968func (n testSpan ) Finish () {}
@@ -90,7 +89,9 @@ func (n testTracer) StartSpan(operationName string, opts ...opentracing.StartSpa
9089func (n testTracer ) startSpanWithOptions (name string , opts opentracing.StartSpanOptions ) opentracing.Span {
9190 fakeID := nextFakeID ()
9291 if len (opts .References ) > 0 {
93- fakeID = opts .References [0 ].ReferencedContext .(testSpanContext ).FakeID
92+ if ctx , ok := opts .References [0 ].ReferencedContext .(testSpanContext ); ok {
93+ fakeID = ctx .FakeID
94+ }
9495 }
9596
9697 return testSpan {
@@ -106,25 +107,37 @@ func (n testTracer) startSpanWithOptions(name string, opts opentracing.StartSpan
106107
107108// Inject belongs to the Tracer interface.
108109func (n testTracer ) Inject (sp opentracing.SpanContext , format interface {}, carrier interface {}) error {
109- spanContext := sp .(testSpanContext )
110+ spanContext , ok := sp .(testSpanContext )
111+ if ! ok {
112+ return opentracing .ErrInvalidSpanContext
113+ }
114+
110115 switch format {
111116 case opentracing .HTTPHeaders , opentracing .TextMap :
112- carrier .(opentracing.TextMapWriter ).Set (testHTTPHeaderPrefix + "fakeid" , strconv .Itoa (spanContext .FakeID ))
117+ writer , ok := carrier .(opentracing.TextMapWriter )
118+ if ! ok {
119+ return opentracing .ErrInvalidCarrier
120+ }
121+ writer .Set (testHTTPHeaderPrefix + "fakeid" , strconv .Itoa (spanContext .FakeID ))
113122 return nil
114123 }
115124 return opentracing .ErrUnsupportedFormat
116125}
117126
118127// Extract belongs to the Tracer interface.
119128func (n testTracer ) Extract (format interface {}, carrier interface {}) (opentracing.SpanContext , error ) {
120- switch format {
121- case opentracing .HTTPHeaders , opentracing .TextMap :
129+ if format == opentracing .HTTPHeaders || format == opentracing .TextMap {
122130 // Just for testing purposes... generally not a worthwhile thing to
123131 // propagate.
124132 sm := testSpanContext {}
125- err := carrier .(opentracing.TextMapReader ).ForeachKey (func (key , val string ) error {
126- switch strings .ToLower (key ) {
127- case testHTTPHeaderPrefix + "fakeid" :
133+ reader , ok := carrier .(opentracing.TextMapReader )
134+ if ! ok {
135+ return nil , opentracing .ErrInvalidCarrier
136+ }
137+
138+ err := reader .ForeachKey (func (key , val string ) error {
139+ lowerKey := strings .ToLower (key )
140+ if lowerKey == testHTTPHeaderPrefix + "fakeid" {
128141 i , err := strconv .Atoi (val )
129142 if err != nil {
130143 return err
0 commit comments