go-macaron / toolbox Goto Github PK
View Code? Open in Web Editor NEWPackage toolbox is a middleware that provides health check, pprof, profile and statistic services for Macaron.
License: Apache License 2.0
Package toolbox is a middleware that provides health check, pprof, profile and statistic services for Macaron.
License: Apache License 2.0
It would be nice to be able to integrate toolbox with other middleware frameworks, like
https://github.com/go-on/wrap without having the macaron dependency.
Can I turn off /debug
somehow? I want the healthchecks and statistics functionality, but I really don't want the profiling stuff when macaron.Env = "production".
在文档里能看到
func (m *UrlMap) GetMap(w io.Writer)
func (m *UrlMap) JSON(w io.Writer)
而用toolbox.Toolbox的时候有GetMap却没有JSON,应该是toolbox:40行这里
type Toolbox interface {
AddHealthCheck(HealthChecker)
AddHealthCheckFunc(string, HealthCheckFunc)
AddStatistics(string, string, time.Duration)
GetMap(io.Writer)
}
这里缺少个
JSON(io.Writer)
首页中的例子:
package main
import (
"github.com/Unknwon/macaron"
"github.com/macaron-contrib/toolbox"
)
func main() {
m := macaron.Classic()
m.Use(toolbox.Toolboxer(m))
m.Run()
}
在新的macaron和toolbox下会出现panic,具体log如下:
[Macaron] Started GET /debug for 127.0.0.1
[Macaron] PANIC: runtime error: invalid memory address or nil pointer dereferenc
e
c:/go/src/runtime/panic.go:387 (0x410816)
c:/go/src/runtime/panic.go:42 (0x40fd85)
c:/go/src/runtime/os_windows.go:42 (0x40fb46)
D:/Software/pkg/src/github.com/macaron-contrib/toolbox/toolbox.go:93 (0x44cac8)
dashboard: </ol>`, opt.PprofURLPrefix, opt.ProfileURLPrefix)))
c:/go/src/runtime/asm_386.s:412 (0x4335c1)
c:/go/src/reflect/value.go:419 (0x4b82d9)
c:/go/src/reflect/value.go:296 (0x4b7465)
D:/Software/pkg/src/github.com/Unknwon/macaron/inject/inject.go:102 (0x4f21aa)
(*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:113 (0x435f90)
(*Context).run: vals, err := c.Invoke(c.handler())
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:104 (0x435ebf)
(*Context).Next: c.run()
D:/Software/pkg/src/github.com/Unknwon/macaron/recovery.go:161 (0x442af8)
func.008: c.Next()
c:/go/src/runtime/asm_386.s:412 (0x4335c1)
c:/go/src/reflect/value.go:419 (0x4b82d9)
c:/go/src/reflect/value.go:296 (0x4b7465)
D:/Software/pkg/src/github.com/Unknwon/macaron/inject/inject.go:102 (0x4f21aa)
(*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:113 (0x435f90)
(*Context).run: vals, err := c.Invoke(c.handler())
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:104 (0x435ebf)
(*Context).Next: c.run()
D:/Software/pkg/src/github.com/Unknwon/macaron/logger.go:40 (0x441cf5)
func.004: ctx.Next()
c:/go/src/runtime/asm_386.s:412 (0x4335c1)
c:/go/src/reflect/value.go:419 (0x4b82d9)
c:/go/src/reflect/value.go:296 (0x4b7465)
D:/Software/pkg/src/github.com/Unknwon/macaron/inject/inject.go:102 (0x4f21aa)
(*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:113 (0x435f90)
(*Context).run: vals, err := c.Invoke(c.handler())
D:/Software/pkg/src/github.com/Unknwon/macaron/router.go:156 (0x442f74)
func.015: c.run()
D:/Software/pkg/src/github.com/Unknwon/macaron/router.go:243 (0x43c489)
(*Router).ServeHTTP: h(rw, req, p)
D:/Software/pkg/src/github.com/Unknwon/macaron/macaron.go:168 (0x439606)
(*Macaron).ServeHTTP: m.Router.ServeHTTP(rw, req)
c:/go/src/net/http/server.go:1703 (0x4971c5)
c:/go/src/net/http/server.go:1204 (0x495348)
c:/go/src/runtime/asm_386.s:2287 (0x4350f1)
[Macaron] Completed /debug 500 Internal Server Error in 5.0003ms
[Macaron] Started GET /favicon.ico for 127.0.0.1
[Macaron] Completed /favicon.ico 404 Not Found in 0
[Macaron] Started GET /debug for [::1]
[Macaron] PANIC: runtime error: invalid memory address or nil pointer dereferenc
e
c:/go/src/runtime/panic.go:387 (0x410816)
c:/go/src/runtime/panic.go:42 (0x40fd85)
c:/go/src/runtime/os_windows.go:42 (0x40fb46)
D:/Software/pkg/src/github.com/macaron-contrib/toolbox/toolbox.go:93 (0x44cac8)
dashboard: </ol>`, opt.PprofURLPrefix, opt.ProfileURLPrefix)))
c:/go/src/runtime/asm_386.s:412 (0x4335c1)
c:/go/src/reflect/value.go:419 (0x4b82d9)
c:/go/src/reflect/value.go:296 (0x4b7465)
D:/Software/pkg/src/github.com/Unknwon/macaron/inject/inject.go:102 (0x4f21aa)
(*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:113 (0x435f90)
(*Context).run: vals, err := c.Invoke(c.handler())
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:104 (0x435ebf)
(*Context).Next: c.run()
D:/Software/pkg/src/github.com/Unknwon/macaron/recovery.go:161 (0x442af8)
func.008: c.Next()
c:/go/src/runtime/asm_386.s:412 (0x4335c1)
c:/go/src/reflect/value.go:419 (0x4b82d9)
c:/go/src/reflect/value.go:296 (0x4b7465)
D:/Software/pkg/src/github.com/Unknwon/macaron/inject/inject.go:102 (0x4f21aa)
(*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:113 (0x435f90)
(*Context).run: vals, err := c.Invoke(c.handler())
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:104 (0x435ebf)
(*Context).Next: c.run()
D:/Software/pkg/src/github.com/Unknwon/macaron/logger.go:40 (0x441cf5)
func.004: ctx.Next()
c:/go/src/runtime/asm_386.s:412 (0x4335c1)
c:/go/src/reflect/value.go:419 (0x4b82d9)
c:/go/src/reflect/value.go:296 (0x4b7465)
D:/Software/pkg/src/github.com/Unknwon/macaron/inject/inject.go:102 (0x4f21aa)
(*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
D:/Software/pkg/src/github.com/Unknwon/macaron/context.go:113 (0x435f90)
(*Context).run: vals, err := c.Invoke(c.handler())
D:/Software/pkg/src/github.com/Unknwon/macaron/router.go:156 (0x442f74)
func.015: c.run()
D:/Software/pkg/src/github.com/Unknwon/macaron/router.go:243 (0x43c489)
(*Router).ServeHTTP: h(rw, req, p)
D:/Software/pkg/src/github.com/Unknwon/macaron/macaron.go:168 (0x439606)
(*Macaron).ServeHTTP: m.Router.ServeHTTP(rw, req)
c:/go/src/net/http/server.go:1703 (0x4971c5)
c:/go/src/net/http/server.go:1204 (0x495348)
c:/go/src/runtime/asm_386.s:2287 (0x4350f1)
[Macaron] Completed /debug 500 Internal Server Error in 5.0003ms
最简单的代码
package main
import (
"time"
"github.com/go-macaron/toolbox"
"gopkg.in/macaron.v1"
)
func main() {
m := macaron.Classic()
m.Use(toolbox.Toolboxer(m))
m.Get("/", func(t *toolbox.Toolbox) {
start := time.Now()
// Other operations.
t.AddStatistics("GET", "/", time.Since(start))
})
m.Run()
}
在go1.5rc1提示.\main.go:18: t.AddStatistics undefined (type *toolbox.Toolbox is pointer to interface, not interface)
新的go-macaron路径和新的中间件不匹配没法一起编译了啊.....
"gopkg.in/macaron.v1"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.