예제 #1
0
func NewLogMiddle(s *stats.Stats) func(http.Handler) http.Handler {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			start := time.Now()
			res := &wrapper{w, 0, 200}
			ip := realip.RealIP(r)

			logger.Infof("[%s] >>> %s %s", ip, r.Method, r.RequestURI)
			h.ServeHTTP(w, r)
			size := humanize.Bytes(uint64(res.written))

			switch {
			case res.status >= 500:
				s.Incr("[error]")
				logger.Errorf(" [%s] << %s %s %d (%s) in %s", ip, r.Method, r.RequestURI,
					res.status, size, time.Since(start))
			case res.status >= 400:
				s.Incr("[error]")
				logger.Warningf(" [%s] << %s %s %d (%s) in %s", ip, r.Method, r.RequestURI,
					res.status, size, time.Since(start))
			default:
				s.Incr("[ok]")
				logger.Infof(" [%s] << %s %s %d (%s) in %s", ip, r.Method, r.RequestURI,
					res.status, size, time.Since(start))
			}
		})
	}
}
예제 #2
0
파일: main.go 프로젝트: inter-rpm/httpdns-1
// HTTPServerDNS is handler of httpdns query
func HTTPServerDNS(w http.ResponseWriter, req *http.Request) {
	domain := req.URL.Query().Get("d")
	if len(domain) == 0 {
		domain = req.Form.Get("d")
		if len(domain) == 0 {
			http.NotFound(w, req)
			return
		}
	}
	w.Write([]byte(QueryDNS(domain, realip.RealIP(req))))
}
예제 #3
0
파일: main.go 프로젝트: inter-rpm/httpdns-1
// HTTPServerMYIP is handler of show-my-ip query
func HTTPServerMYIP(w http.ResponseWriter, req *http.Request) {
	w.Write([]byte(realip.RealIP(req)))
}