Skip to content

Commit

Permalink
use function instead of global var (#36)
Browse files Browse the repository at this point in the history
* use function instead of global var

* fix lack return
  • Loading branch information
thinkerou authored and rghetia committed Jul 1, 2019
1 parent 252c6b5 commit a606839
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions api/tag/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ type Map interface {

type Option func(*registeredKey)

var (
EmptyMap = NewMap(core.KeyValue{}, nil, core.Mutator{}, nil)
)

func New(name string, opts ...Option) core.Key { // TODO rename NewKey?
return register(name, opts)
}
Expand All @@ -49,6 +45,11 @@ func NewMeasure(name string, opts ...Option) core.Measure {
}
}

func NewEmptyMap() Map {
var t tagMap
return t.Apply(core.KeyValue{}, nil, core.Mutator{}, nil)
}

func NewMap(a1 core.KeyValue, attributes []core.KeyValue, m1 core.Mutator, mutators []core.Mutator) Map {
var t tagMap
return t.Apply(a1, attributes, m1, mutators)
Expand Down
10 changes: 5 additions & 5 deletions exporter/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (ro *readerObserver) Observe(event observer.Event) {
read := Event{
Time: event.Time,
Sequence: event.Sequence,
Attributes: tag.EmptyMap,
Tags: tag.EmptyMap,
Attributes: tag.NewEmptyMap(),
Tags: tag.NewEmptyMap(),
}

if event.Context != nil {
Expand Down Expand Up @@ -201,7 +201,7 @@ func (ro *readerObserver) Observe(event observer.Event) {
sid = event.Scope
}
if sid.EventID == 0 {
m = tag.EmptyMap
m = tag.NewEmptyMap()
} else {
parentI, has := ro.scopes.Load(sid.EventID)
if !has {
Expand Down Expand Up @@ -316,7 +316,7 @@ func (ro *readerObserver) addMeasurement(e *Event, m core.Measurement) {

func (ro *readerObserver) readScope(id core.ScopeID) (tag.Map, *readerSpan) {
if id.EventID == 0 {
return tag.EmptyMap, nil
return tag.NewEmptyMap(), nil
}
ev, has := ro.scopes.Load(id.EventID)
if !has {
Expand All @@ -327,7 +327,7 @@ func (ro *readerObserver) readScope(id core.ScopeID) (tag.Map, *readerSpan) {
} else if sp, ok := ev.(*readerSpan); ok {
return sp.attributes, sp
}
return tag.EmptyMap, nil
return tag.NewEmptyMap(), nil
}

func (ro *readerObserver) cleanupSpan(id core.EventID) {
Expand Down

0 comments on commit a606839

Please sign in to comment.