예제 #1
0
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")
}
예제 #2
0
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")
}
예제 #3
0
파일: main.go 프로젝트: jacksonh/go-horizon
// 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
}