chore: Format code
This commit is contained in:
parent
188b7905f5
commit
64b4de8b8a
1 changed files with 7 additions and 7 deletions
|
|
@ -9,15 +9,15 @@ import (
|
||||||
func LoggingMiddleware(next http.Handler) http.Handler {
|
func LoggingMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// Create a response writer wrapper to capture status code
|
// Create a response writer wrapper to capture status code
|
||||||
wrapper := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
|
wrapper := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
|
||||||
|
|
||||||
next.ServeHTTP(wrapper, r)
|
next.ServeHTTP(wrapper, r)
|
||||||
|
|
||||||
duration := time.Since(start)
|
duration := time.Since(start)
|
||||||
timestamp := time.Now().Format(time.RFC3339)
|
timestamp := time.Now().Format(time.RFC3339)
|
||||||
|
|
||||||
log.Printf("[%s] %s %s - %d (%v)", timestamp, r.Method, r.URL.Path, wrapper.statusCode, duration)
|
log.Printf("[%s] %s %s - %d (%v)", timestamp, r.Method, r.URL.Path, wrapper.statusCode, duration)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -32,12 +32,12 @@ func CORSMiddleware(next http.Handler) http.Handler {
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
w.Header().Set("Access-Control-Max-Age", "86400")
|
w.Header().Set("Access-Control-Max-Age", "86400")
|
||||||
|
|
||||||
if r.Method == http.MethodOptions {
|
if r.Method == http.MethodOptions {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -50,4 +50,4 @@ type responseWriter struct {
|
||||||
func (rw *responseWriter) WriteHeader(code int) {
|
func (rw *responseWriter) WriteHeader(code int) {
|
||||||
rw.statusCode = code
|
rw.statusCode = code
|
||||||
rw.ResponseWriter.WriteHeader(code)
|
rw.ResponseWriter.WriteHeader(code)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue