Skip to content

Commit

Permalink
fix test bugs & add dep vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt committed Sep 25, 2017
1 parent f68ff00 commit 8bdaf79
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
vendor/
57 changes: 57 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/labstack/echo"
version = "3.2.3"
26 changes: 13 additions & 13 deletions pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/labstack/echo"
)

// Wrap adds several routes from package `net/http/pprof` to *echo.Echo object
// Wrap adds several routes from package `net/http/pprof` to *echo.Echo object.
func Wrap(e *echo.Echo) {
WrapGroup("", e.Group(""))
}

// Wrapper make sure we are backward compatible
// Wrapper make sure we are backward compatible.
var Wrapper = Wrap

// WrapGroup adds several routes from package `net/http/pprof` to *echo.Group object
// WrapGroup adds several routes from package `net/http/pprof` to *echo.Group object.
func WrapGroup(prefix string, g *echo.Group) {
routers := []struct {
Method string
Expand Down Expand Up @@ -45,79 +45,79 @@ func WrapGroup(prefix string, g *echo.Group) {
}
}

// IndexHandler will pass the call from /debug/pprof to pprof
// IndexHandler will pass the call from /debug/pprof to pprof.
func IndexHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Index(ctx.Response().Writer, ctx.Request())
return nil
}
}

// HeapHandler will pass the call from /debug/pprof/heap to pprof
// HeapHandler will pass the call from /debug/pprof/heap to pprof.
func HeapHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Handler("heap").ServeHTTP(ctx.Response(), ctx.Request())
return nil
}
}

// GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof
// GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof.
func GoroutineHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Handler("goroutine").ServeHTTP(ctx.Response().Writer, ctx.Request())
return nil
}
}

// BlockHandler will pass the call from /debug/pprof/block to pprof
// BlockHandler will pass the call from /debug/pprof/block to pprof.
func BlockHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Handler("block").ServeHTTP(ctx.Response().Writer, ctx.Request())
return nil
}
}

// ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof
// ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof.
func ThreadCreateHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Handler("threadcreate").ServeHTTP(ctx.Response().Writer, ctx.Request())
return nil
}
}

// CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof
// CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof.
func CmdlineHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Cmdline(ctx.Response().Writer, ctx.Request())
return nil
}
}

// ProfileHandler will pass the call from /debug/pprof/profile to pprof
// ProfileHandler will pass the call from /debug/pprof/profile to pprof.
func ProfileHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Profile(ctx.Response().Writer, ctx.Request())
return nil
}
}

// SymbolHandler will pass the call from /debug/pprof/symbol to pprof
// SymbolHandler will pass the call from /debug/pprof/symbol to pprof.
func SymbolHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Symbol(ctx.Response().Writer, ctx.Request())
return nil
}
}

// TraceHandler will pass the call from /debug/pprof/trace to pprof
// TraceHandler will pass the call from /debug/pprof/trace to pprof.
func TraceHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Trace(ctx.Response().Writer, ctx.Request())
return nil
}
}

// MutexHandler will pass the call from /debug/pprof/mutex to pprof
// MutexHandler will pass the call from /debug/pprof/mutex to pprof.
func MutexHandler() echo.HandlerFunc {
return func(ctx echo.Context) error {
pprof.Handler("mutex").ServeHTTP(ctx.Response().Writer, ctx.Request())
Expand Down
7 changes: 3 additions & 4 deletions pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func newServer() *echo.Echo {
return e
}

func checkRouters(routers []echo.Route, t *testing.T) {
func checkRouters(routers []*echo.Route, t *testing.T) {
expectedRouters := map[string]string{
"/debug/pprof/": "IndexHandler",
"/debug/pprof/heap": "HeapHandler",
Expand All @@ -34,8 +34,8 @@ func checkRouters(routers []echo.Route, t *testing.T) {
if !ok {
t.Errorf("missing router %s", router.Path)
}
if !strings.Contains(router.Handler, name) {
t.Errorf("handler for %s should contain %s, got %s", router.Path, name, router.Handler)
if !strings.Contains(router.Name, name) {
t.Errorf("handler for %s should contain %s, got %s", router.Path, name, router.Name)
}
}
}
Expand All @@ -50,7 +50,6 @@ func TestWrap(t *testing.T) {
// go test github.com/sevenNt/echo-pprof -v -run=TestWrapGroup\$
func TestWrapGroup(t *testing.T) {
for _, prefix := range []string{"/debug"} {
//for _, prefix := range []string{"/debug", "/debug/", "/debug/pprof", "/debug/pprof/"} {
e := newServer()
g := e.Group(prefix)
WrapGroup(prefix, g)
Expand Down

0 comments on commit 8bdaf79

Please sign in to comment.