https://github.com/feixiao/httpprof
add pprof to httprouter
https://github.com/feixiao/httpprof
golang httprouter pprof
Last synced: 3 months ago
JSON representation
add pprof to httprouter
- Host: GitHub
- URL: https://github.com/feixiao/httpprof
- Owner: feixiao
- License: mit
- Created: 2017-07-18T02:51:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-18T03:11:38.000Z (over 8 years ago)
- Last Synced: 2025-04-19T10:08:52.550Z (11 months ago)
- Topics: golang, httprouter, pprof
- Language: Go
- Size: 1.95 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
README
## 给httprouter添加pprof
1:获取包
```sh
go get github.com/feixiao/httpprof
```
2:进入所在目录,获取依赖
```
govendor sync
```
3:编译运行example
```
go build
```
4:外部项目添加使用,只需要参考example的使用即可
```go
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}
func main() {
router := httprouter.New()
// 在原来的httprouter的使用基础只是添加了这一句代码
router = httpprof.WrapRouter(router)
router.GET("/", Index)
router.GET("/hello/:name", Hello)
log.Fatal(http.ListenAndServe(":8080", router))
}
```