many fixes for lint and context.Context usage (#5)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-11-03 02:02:32 +03:00
committed by GitHub
parent 40b0870cf8
commit 8a2b122015
44 changed files with 152 additions and 1175 deletions

View File

@@ -2,24 +2,34 @@ package tracer
import "context"
type NoopTracer struct{}
type noopTracer struct {
opts Options
}
func (n *NoopTracer) Init(...Option) error {
// Init initilize tracer
func (n *noopTracer) Init(opts ...Option) error {
for _, o := range opts {
o(&n.opts)
}
return nil
}
func (n *NoopTracer) Start(ctx context.Context, name string) (context.Context, *Span) {
// Start starts new span
func (n *noopTracer) Start(ctx context.Context, name string) (context.Context, *Span) {
return nil, nil
}
func (n *NoopTracer) Finish(*Span) error {
// Finish finishes span
func (n *noopTracer) Finish(*Span) error {
return nil
}
func (n *NoopTracer) Read(...ReadOption) ([]*Span, error) {
// Read reads span
func (n *noopTracer) Read(...ReadOption) ([]*Span, error) {
return nil, nil
}
// NewTracer returns new noop tracer
func NewTracer(opts ...Option) Tracer {
return &NoopTracer{}
return &noopTracer{opts: NewOptions(opts...)}
}

View File

@@ -1,5 +1,10 @@
package tracer
var (
// DefaultSize of the buffer
DefaultSize = 64
)
// Options struct
type Options struct {
// Size is the size of ring buffer
@@ -9,6 +14,7 @@ type Options struct {
// Option func
type Option func(o *Options)
// ReadOptions struct
type ReadOptions struct {
// Trace id
Trace string
@@ -24,14 +30,13 @@ func ReadTrace(t string) ReadOption {
}
}
const (
// DefaultSize of the buffer
DefaultSize = 64
)
// DefaultOptions returns default options
func DefaultOptions() Options {
return Options{
// NewOptions returns default options
func NewOptions(opts ...Option) Options {
options := Options{
Size: DefaultSize,
}
for _, o := range opts {
o(&options)
}
return options
}

View File

@@ -1,4 +1,4 @@
// Package trace provides an interface for distributed tracing
// Package tracer provides an interface for distributed tracing
package tracer
import (
@@ -7,6 +7,7 @@ import (
)
var (
// DefaultTracer is the global default tracer
DefaultTracer Tracer = NewTracer()
)