Explorar el Código

Move request log printing into the log function

Lu Stadler %!s(int64=7) %!d(string=hace) años
padre
commit
7cd3b8c5df
Se han modificado 1 ficheros con 3 adiciones y 3 borrados
  1. 3 3
      go/fake-http/fake-http.go

+ 3 - 3
go/fake-http/fake-http.go

@ -66,9 +66,6 @@ func main() {
66 66
			resp = respondWithStub(responses, w, req)
67 67
		}
68 68
69
		userAgent := req.Header.Get("User-Agent")
70
		log.Printf("%s %s - %d (%s, %q)", req.Method, req.URL, resp.StatusCode, req.RemoteAddr, userAgent)
71
72 69
		requestLog.Log(req, resp)
73 70
	})
74 71
@ -227,6 +224,9 @@ type Log []LogEntry
227 224
228 225
// Log logs the request/response pair.
229 226
func (l *Log) Log(req *http.Request, resp *http.Response) {
227
	userAgent := req.Header.Get("User-Agent")
228
	log.Printf("%s %s - %d (%s, %q)", req.Method, req.URL, resp.StatusCode, req.RemoteAddr, userAgent)
229
230 230
	e := LogEntry{
231 231
		request:      req,
232 232
		requestBody:  new(bytes.Buffer),