Giter Site home page Giter Site logo

go-macaron / toolbox Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 4.0 31 KB

Package toolbox is a middleware that provides health check, pprof, profile and statistic services for Macaron.

License: Apache License 2.0

Go 100.00%
go lsif-enabled macaron middleware toolbox

toolbox's People

Contributors

ipfans avatar unknwon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

toolbox's Issues

Add option to disable pprof and profile

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".

Toolbox缺少JSON函数

在文档里能看到

 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

无法通过编译 t.AddStatistics undefined (type *toolbox.Toolbox is pointer to interface, not interface)

最简单的代码

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.