goji 默认对每个请求都输出请求时间,要想关掉log,有两个方法:
第一种
1
2
3
4
5
6
7
8
import (
"log"
"io/ioutil"
)
func init() {
log.SetOutput(ioutil.Discard)
}
第二种
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main
import (
"fmt"
"net/http"
"github.com/zenazn/goji"
"github.com/zenazn/goji/web"
"github.com/zenazn/goji/web/middleware" // add line 1
)
func hello(c web.C, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"])
}
func main() {
goji.Abandon(middleware.Logger) // add line 2
goji.Get("/hello/:name", hello)
goji.Serve()
}
本文网址: https://pylist.com/topic/87.html 转摘请注明来源