From 8bdaf794e4583c013a089f3902aa140d45a5af1c Mon Sep 17 00:00:00 2001 From: sevenNt Date: Mon, 25 Sep 2017 16:54:15 +0800 Subject: [PATCH] fix test bugs & add dep vendor --- .gitignore | 1 + Gopkg.lock | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ Gopkg.toml | 26 +++++++++++++++++++++++ pprof.go | 26 +++++++++++------------ pprof_test.go | 7 +++---- 5 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml diff --git a/.gitignore b/.gitignore index 9f11b75..4c36e38 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +vendor/ diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..d94131a --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,57 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/labstack/echo" + packages = ["."] + revision = "cec7629194fe4bf83b0c72d9a02d340c7a1468ac" + version = "3.2.3" + +[[projects]] + name = "github.com/labstack/gommon" + packages = ["color","log"] + revision = "57409ada9da0f2afad6664c49502f8c50fbd8476" + version = "0.2.3" + +[[projects]] + name = "github.com/mattn/go-colorable" + packages = ["."] + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" + +[[projects]] + name = "github.com/mattn/go-isatty" + packages = ["."] + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + branch = "master" + name = "github.com/valyala/bytebufferpool" + packages = ["."] + revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7" + +[[projects]] + branch = "master" + name = "github.com/valyala/fasttemplate" + packages = ["."] + revision = "dcecefd839c4193db0d35b88ec65b4c12d360ab0" + +[[projects]] + branch = "master" + name = "golang.org/x/crypto" + packages = ["acme","acme/autocert"] + revision = "7d9177d70076375b9a59c8fde23d52d9c4a7ecd5" + +[[projects]] + branch = "master" + name = "golang.org/x/sys" + packages = ["unix"] + revision = "429f518978ab01db8bb6f44b66785088e7fba58b" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "c5940a0eeeeed01345307ad7603c5459f83f45513d1c334546beb3dd77b11e0f" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..443f035 --- /dev/null +++ b/Gopkg.toml @@ -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" diff --git a/pprof.go b/pprof.go index 98855ec..390699b 100644 --- a/pprof.go +++ b/pprof.go @@ -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 @@ -45,7 +45,7 @@ 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()) @@ -53,7 +53,7 @@ func IndexHandler() echo.HandlerFunc { } } -// 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()) @@ -61,7 +61,7 @@ func HeapHandler() echo.HandlerFunc { } } -// 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()) @@ -69,7 +69,7 @@ func GoroutineHandler() echo.HandlerFunc { } } -// 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()) @@ -77,7 +77,7 @@ func BlockHandler() echo.HandlerFunc { } } -// 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()) @@ -85,7 +85,7 @@ func ThreadCreateHandler() echo.HandlerFunc { } } -// 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()) @@ -93,7 +93,7 @@ func CmdlineHandler() echo.HandlerFunc { } } -// 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()) @@ -101,7 +101,7 @@ func ProfileHandler() echo.HandlerFunc { } } -// 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()) @@ -109,7 +109,7 @@ func SymbolHandler() echo.HandlerFunc { } } -// 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()) @@ -117,7 +117,7 @@ func TraceHandler() echo.HandlerFunc { } } -// 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()) diff --git a/pprof_test.go b/pprof_test.go index 75d62d7..e5fb2cd 100644 --- a/pprof_test.go +++ b/pprof_test.go @@ -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", @@ -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) } } } @@ -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)