1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | toolbox ======= Middleware toolbox provides health chcek, pprof, profile and statistic services for [Macaron](https://github.com/go-macaron/macaron). [API Reference](https://gowalker.org/github.com/go-macaron/toolbox) ### Installation go get github.com/go-macaron/toolbox ## Usage ```go // main.go import ( "gopkg.in/macaron.v1" "github.com/go-macaron/toolbox" ) func main() { m := macaron.Classic() m.Use(toolbox.Toolboxer(m)) m.Run() } ``` Open your browser and visit `http://localhost:4000/debug` to see the effects. ## Options `toolbox.Toolboxer` comes with a variety of configuration options: ```go type dummyChecker struct { } func (dc *dummyChecker) Desc() string { return "Dummy checker" } func (dc *dummyChecker) Check() error { return nil } // ... m.Use(toolbox.Toolboxer(m, toolbox.Options{ URLPrefix: "/debug", // URL prefix for toolbox dashboard. HealthCheckURL: "/healthcheck", // URL for health check request. HealthCheckers: []HealthChecker{ new(dummyChecker), }, // Health checkers. HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{ &toolbox.HealthCheckFuncDesc{ Desc: "Database connection", Func: func() error { return "OK" }, }, }, // Health check functions. PprofURLPrefix: "/debug/pprof/", // URL prefix of pprof. ProfileURLPrefix: "/debug/profile/", // URL prefix of profile. ProfilePath: "profile", // Path store profile files. })) // ... ``` ## Route Statistic Toolbox also comes with a route call statistic functionality: ```go import ( "os" "time" //... "github.com/go-macaron/toolbox" ) func main() { //... m.Get("/", func(t toolbox.Toolbox) { start := time.Now() // Other operations. t.AddStatistics("GET", "/", time.Since(start)) }) m.Get("/dump", func(t toolbox.Toolbox) { t.GetMap(os.Stdout) }) } ``` Output take from test: ``` +---------------------------------------------------+------------+------------------+------------------+------------------+------------------+------------------+ | Request URL | Method | Times | Total Used(s) | Max Used(μs) | Min Used(μs) | Avg Used(μs) | +---------------------------------------------------+------------+------------------+------------------+------------------+------------------+------------------+ | /api/user | POST | 2 | 0.000122 | 120.000000 | 2.000000 | 61.000000 | | /api/user | GET | 1 | 0.000013 | 13.000000 | 13.000000 | 13.000000 | | /api/user | DELETE | 1 | 0.000001 | 1.400000 | 1.400000 | 1.400000 | | /api/admin | POST | 1 | 0.000014 | 14.000000 | 14.000000 | 14.000000 | | /api/user/unknwon | POST | 1 | 0.000012 | 12.000000 | 12.000000 | 12.000000 | +---------------------------------------------------+------------+------------------+------------------+------------------+------------------+------------------+ ``` ## License This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text. |
Commit History @debian/0.0_git20170220.0.6766b8f-6
0
»»
- update debian/gitlab-ci.yml (using salsa.debian.org/go-team/ci/cmd/ci) Michael Stapelberg 6 years ago
- point Vcs-* urls to salsa.debian.org aviau 6 years ago
- Remove Michael Lustfield from Uploaders list. Michael Lustfield 6 years ago
- Finalizing d/changelog for release. Michael Lustfield 6 years ago
- Orphaning dependency of gitea; no longer maintaining gitea. Michael Lustfield 6 years ago
- Finalize d/changelog for upload. Michael Lustfield 6 years ago
- Packaging clean-up and maintenance. Michael Lustfield 6 years ago
- Finalizing d/changelog for upload. Michael Lustfield 7 years ago
- Removing profiling output from build and re-uploading. (reprobuild) Michael Lustfield 7 years ago
- Finalizing d/changelog for release. Michael Lustfield 7 years ago
- Dropping comma from d/copyright (dep5). Michael Lustfield 7 years ago
- Initial packaging. Michael Lustfield 7 years ago
- Ignore quilt dir .pc via .gitignore Michael Lustfield 7 years ago
- New upstream version 0.0~git20170220.0.6766b8f Michael Lustfield 7 years ago
0
»»