INNER CODE UNIT · Go

logRequest

apache/apisix · t/sse_server_example/main.go:121

func logRequest(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		next(w, r)
		duration := time.Since(start)

		log.Printf("%s %s - Duration: %s", r.Method, r.URL.Path, duration)
	}
}

var counter = 0

func main() {
	http.HandleFunc("/v1/chat/completions", logRequest(completionsHandler))
	http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		w.Write([]byte("OK"))
	})

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…