package utils import "net/http" func WithCORS(h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type") w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, DELETE, POST, OPTIONS") if r.Method == http.MethodOptions { w.WriteHeader(http.StatusOK) return } h(w, r) } } func WithCORSHandler(h http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type") w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, DELETE, POST, OPTIONS") if r.Method == http.MethodOptions { w.WriteHeader(http.StatusOK) return } h.ServeHTTP(w, r) } }