Просмотр исходного кода

Move request log printing into the log function

Lu Stadler лет назад: 7
Родитель
Сommit
7cd3b8c5df
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      go/fake-http/fake-http.go

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

66
			resp = respondWithStub(responses, w, req)
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
		requestLog.Log(req, resp)
69
		requestLog.Log(req, resp)
73
	})
70
	})
74
71
227
224
228
// Log logs the request/response pair.
225
// Log logs the request/response pair.
229
func (l *Log) Log(req *http.Request, resp *http.Response) {
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
	e := LogEntry{
230
	e := LogEntry{
231
		request:      req,
231
		request:      req,
232
		requestBody:  new(bytes.Buffer),
232
		requestBody:  new(bytes.Buffer),