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

Move converting to response definitions onto the log

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

+ 10 - 5
go/fake-http/fake-http.go

@ -71,11 +71,7 @@ func main() {
71 71
72 72
	http.HandleFunc("/_log", func(w http.ResponseWriter, req *http.Request) {
73 73
		if strings.Contains(req.Header.Get("Accept"), "application/yaml") {
74
			rrs := make([]Response, len(requestLog))
75
			for i, log := range requestLog {
76
				rs[i] = log.AsResponse()
77
			}
78
			err := renderYAML(w, rs)
74
			errr := renderYAML(w, requestLog.AsResponses())
79 75
			if err != nil {
80 76
				log.Printf("Error: Render log: %s", err)
81 77
			}
@ -247,6 +243,15 @@ func (l *Log) Log(req *http.Request, resp *http.Response) {
247 243
	*l = append(*l, e)
248 244
}
249 245
246
// AsResponses returns the log as a list of response definition.
247
func (l *Log) AsResponses() []Response {
248
	rs := make([]Response, len(*l))
249
	for i, log := range *l {
250
		rs[i] = log.AsResponse()
251
	}
252
	return rs
253
}
254
250 255
// LogEntry is a request/response pair for logging.
251 256
type LogEntry struct {
252 257
	request      *http.Request