Compare commits
4 Commits
27e8043fed
...
v4.0.4
Author | SHA1 | Date | |
---|---|---|---|
654d8fa7e4 | |||
dd1a9cd25a | |||
d463eb20cb | |||
8d5e25f8cf |
@@ -39,8 +39,6 @@ func FromOutgoingContext(ctx context.Context) (Metadata, bool) {
|
|||||||
|
|
||||||
// FromContext returns metadata from the given context
|
// FromContext returns metadata from the given context
|
||||||
// returned metadata shoud not be modified or race condition happens
|
// returned metadata shoud not be modified or race condition happens
|
||||||
//
|
|
||||||
// Deprecated: use FromIncomingContext or FromOutgoingContext
|
|
||||||
func FromContext(ctx context.Context) (Metadata, bool) {
|
func FromContext(ctx context.Context) (Metadata, bool) {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -53,8 +51,6 @@ func FromContext(ctx context.Context) (Metadata, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewContext creates a new context with the given metadata
|
// NewContext creates a new context with the given metadata
|
||||||
//
|
|
||||||
// Deprecated: use NewIncomingContext or NewOutgoingContext
|
|
||||||
func NewContext(ctx context.Context, md Metadata) context.Context {
|
func NewContext(ctx context.Context, md Metadata) context.Context {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
|
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ Tracer = (*noopTracer)(nil)
|
||||||
|
|
||||||
type noopTracer struct {
|
type noopTracer struct {
|
||||||
opts Options
|
opts Options
|
||||||
}
|
}
|
||||||
@@ -21,6 +23,10 @@ func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption)
|
|||||||
return NewSpanContext(ctx, span), span
|
return NewSpanContext(ctx, span), span
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *noopTracer) Flush(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *noopTracer) Init(opts ...Option) error {
|
func (t *noopTracer) Init(opts ...Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&t.opts)
|
o(&t.opts)
|
||||||
|
@@ -16,6 +16,8 @@ type Tracer interface {
|
|||||||
Init(...Option) error
|
Init(...Option) error
|
||||||
// Start a trace
|
// Start a trace
|
||||||
Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
|
Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
|
||||||
|
// Flush flushes spans
|
||||||
|
Flush(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Span interface {
|
type Span interface {
|
||||||
|
@@ -21,7 +21,6 @@ loop:
|
|||||||
for i, r := range s {
|
for i, r := range s {
|
||||||
switch r {
|
switch r {
|
||||||
case 's', 'm':
|
case 's', 'm':
|
||||||
p = i
|
|
||||||
break loop
|
break loop
|
||||||
case 'h':
|
case 'h':
|
||||||
d, err := strconv.Atoi(s[p:i])
|
d, err := strconv.Atoi(s[p:i])
|
||||||
@@ -68,7 +67,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
|
|||||||
*d = Duration(time.Duration(value))
|
*d = Duration(time.Duration(value))
|
||||||
return nil
|
return nil
|
||||||
case string:
|
case string:
|
||||||
dv, err := time.ParseDuration(value)
|
dv, err := ParseDuration(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -23,13 +23,21 @@ func TestUnmarshalJSON(t *testing.T) {
|
|||||||
TTL Duration `json:"ttl"`
|
TTL Duration `json:"ttl"`
|
||||||
}
|
}
|
||||||
v := &str{}
|
v := &str{}
|
||||||
|
var err error
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(`{"ttl":"10ms"}`), v)
|
err = json.Unmarshal([]byte(`{"ttl":"10ms"}`), v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if v.TTL != 10000000 {
|
} else if v.TTL != 10000000 {
|
||||||
t.Fatalf("invalid duration %v != 10000000", v.TTL)
|
t.Fatalf("invalid duration %v != 10000000", v.TTL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(`{"ttl":"1y"}`), v)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if v.TTL != 31536000000000000 {
|
||||||
|
t.Fatalf("invalid duration %v != 31536000000000000", v.TTL)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDuration(t *testing.T) {
|
func TestParseDuration(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user