// ServeHTTP makes Handler fit the http.Handler interface.
ServeHTTP makes Handler fit the http.Handler interface.
// ServeHTTP makes Handler fit the http . Handler interface .
func (handler Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var trace Trace
	trace.initialize()
	w.Header().Add(httpResponseTraceIDHeaderName, string(trace.ID[:]))
	subhandler := handler.Subhandler
	if nil == subhandler {
		subhandler = notFoundHandler
	}
	writer := handler.Writer
	if nil == writer {
		writer = os.Stdout
	}
	var w2 ResponseWriter = ResponseWriter{w:w}
	ctx := r.Context()
	if nil == ctx {
		http.Error(w, "Internal Server Error", http.StatusInternalServerError)
		return
	}
	newCTX := context.WithValue(ctx, traceIDContextKey, string(trace.ID[:]))
	r2 := r.WithContext(newCTX)
	subhandler.ServeHTTP(&w2, r2)
	trace.EndTime = time.Now()
	writeLog := handler.AccessLogWriter
	if nil == writeLog {
		writeLog = DefaultAccessLogWriter
	}
	writeLog(writer, &w2, r, &trace)
}
func ( handler Handler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) { var trace Trace trace . initialize ( ) w . Header ( ) . Add ( httpResponseTraceIDHeaderName , string ( trace . ID [ : ] ) ) subhandler := handler . Subhandler if nil == subhandler { subhandler = notFoundHandler } writer := handler . Writer if nil == writer { writer = os . Stdout } var w2 ResponseWriter = ResponseWriter { w : w } ctx := r . Context ( ) if nil == ctx { http . Error ( w , " " , http . StatusInternalServerError ) return } newCTX := context . WithValue ( ctx , traceIDContextKey , string ( trace . ID [ : ] ) ) r2 := r . WithContext ( newCTX ) subhandler . ServeHTTP ( & w2 , r2 ) trace . EndTime = time . Now ( ) writeLog := handler . AccessLogWriter if nil == writeLog { writeLog = DefaultAccessLogWriter } writeLog ( writer , & w2 , r , & trace ) }
ServeHTTP makes Handler fit the http.Handler interface.
ServeHTTP makes Handler fit the http . Handler interface .
// This sets trace.BeginTime and trace.ID, but NOT trace.EndTime. // trace.EndTime is set latter in this func.