func logStartOfRequest(ctx context.Context, r *http.Request) { fields := logrus.Fields{ "path": r.URL.String(), "method": r.Method, } log.WithFields(ctx, fields).Info("Starting request") }
func logEndOfRequest(ctx context.Context, duration time.Duration, mw mutil.WriterProxy) { fields := logrus.Fields{ "status": mw.Status(), "bytes": mw.BytesWritten(), "duration": duration, } log.WithFields(ctx, fields).Info("Finished request") }
// Negotiate inspects the Accept header of the provided request and determines // what the most appropriate response type should be. Defaults to HAL. func Negotiate(ctx context.Context, r *http.Request) string { alternatives := []string{MimeHal, MimeJSON, MimeEventStream} accept := r.Header.Get("Accept") if accept == "" { return MimeHal } result := goautoneg.Negotiate(r.Header.Get("Accept"), alternatives) log.WithFields(ctx, logrus.Fields{ "content_type": result, "accept": accept, }).Debug("Negotiated content type") return result }