Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var xh xhandler.HandlerC
// Here is your handler
xh = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get the xstats request's instance from the context. You can safely assume it will
// be always there, if the handler is removed, xstats.FromContext will return a nop
// be always there, if the handler is removed, xstats.FromContext will return a Nop
// instance.
m := xstats.FromRequest(r)

Expand Down
6 changes: 3 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ func NewContext(ctx context.Context, xs XStater) context.Context {
}

// FromContext retreives the request's xstats client from a given context if any.
// If no xstats is embeded in the context, a nop instance is returned so you can
// If no xstats is embeded in the context, a Nop instance is returned so you can
// use it safely without having to test for it's presence.
func FromContext(ctx context.Context) XStater {
rc, ok := ctx.Value(xstatsKey).(XStater)
if ok {
return rc
}
return nop
return Nop
}

// FromRequest gets the xstats client in the request's context.
// This is a shortcut for xstats.FromContext(r.Context())
func FromRequest(r *http.Request) XStater {
if r == nil {
return nop
return Nop
}
return FromContext(r.Context())
}
Expand Down
2 changes: 1 addition & 1 deletion handler_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ExampleNewHandler() {
// Here is your handler
h := c.HandlerH(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get the xstats request's instance from the context. You can safely assume it will
// be always there, if the handler is removed, xstats.FromContext will return a nop
// be always there, if the handler is removed, xstats.FromContext will return a Nop
// instance.
m := xstats.FromRequest(r)

Expand Down
4 changes: 2 additions & 2 deletions handler_pre17.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func NewContext(ctx context.Context, xs XStater) context.Context {
}

// FromContext retreives the request's xstats client from a given context if any.
// If no xstats is embeded in the context, a nop instance is returned so you can
// If no xstats is embeded in the context, a Nop instance is returned so you can
// use it safely without having to test for it's presence.
func FromContext(ctx context.Context) XStater {
rc, ok := ctx.Value(xstatsKey).(XStater)
if ok {
return rc
}
return nop
return Nop
}

// NewHandler creates a new handler with the provided metric client.
Expand Down
2 changes: 1 addition & 1 deletion nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
type nopS struct {
}

var nop = &nopS{}
var Nop = &nopS{}

// AddTags implements XStats interface
func (rc *nopS) AddTags(tags ...string) {
Expand Down
10 changes: 5 additions & 5 deletions nop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

func TestNop(t *testing.T) {
nop.AddTags("tag")
nop.Gauge("metric", 1)
nop.Count("metric", 1)
nop.Histogram("metric", 1)
nop.Timing("metric", 1*time.Second)
Nop.AddTags("tag")
Nop.Gauge("metric", 1)
Nop.Count("metric", 1)
Nop.Histogram("metric", 1)
Nop.Timing("metric", 1*time.Second)
}
8 changes: 4 additions & 4 deletions xstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ func NewScoping(s Sender, delimiter string, scopes ...string) XStater {
}

// Copy makes a copy of the given XStater if it implements the Copier
// interface. Otherwise it returns a nop stats.
// interface. Otherwise it returns a Nop stats.
func Copy(xs XStater) XStater {
if c, ok := xs.(Copier); ok {
return c.Copy()
}
return nop
return Nop
}

// Scope makes a scoped copy of the given XStater if it implements the Scoper
// interface. Otherwise it returns a nop stats.
// interface. Otherwise it returns a Nop stats.
func Scope(xs XStater, scope string, scopes ...string) XStater {
if c, ok := xs.(Scoper); ok {
return c.Scope(scope, scopes...)
}
return nop
return Nop
}

// Close will call Close() on any xstats.XStater that implements io.Closer
Expand Down
10 changes: 5 additions & 5 deletions xstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *fakeSendCloser) Close() error {
func TestContext(t *testing.T) {
ctx := context.Background()
s := FromContext(ctx)
assert.Equal(t, nop, s)
assert.Equal(t, Nop, s)

ctx = context.Background()
xs := &xstats{}
Expand Down Expand Up @@ -118,8 +118,8 @@ func TestCopy(t *testing.T) {
assert.Equal(t, []string{"foo"}, xs.tags)
assert.Equal(t, []string{"foo", "bar", "baz"}, xs2.tags)

assert.Equal(t, nop, Copy(nop))
assert.Equal(t, nop, Copy(nil))
assert.Equal(t, Nop, Copy(Nop))
assert.Equal(t, Nop, Copy(nil))
}

func TestScope(t *testing.T) {
Expand All @@ -142,8 +142,8 @@ func TestScope(t *testing.T) {
assert.Equal(t, []string{"foo", "bar", "baz"}, xs2.tags)
assert.Equal(t, []string{"foo", "blegga"}, xs3.tags)

assert.Equal(t, nop, Scope(nop, "prefix"))
assert.Equal(t, nop, Scope(nil, "prefix"))
assert.Equal(t, Nop, Scope(Nop, "prefix"))
assert.Equal(t, Nop, Scope(nil, "prefix"))
}

func TestAddTag(t *testing.T) {
Expand Down