corsMiddleware 添加CORS头(开发时需要)
(next http.Handler)
| 110 | |
| 111 | // corsMiddleware 添加CORS头(开发时需要) |
| 112 | func corsMiddleware(next http.Handler) http.Handler { |
| 113 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 114 | w.Header().Set("Access-Control-Allow-Origin", "*") |
| 115 | w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") |
| 116 | w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") |
| 117 | |
| 118 | if r.Method == "OPTIONS" { |
| 119 | w.WriteHeader(http.StatusOK) |
| 120 | return |
| 121 | } |
| 122 | |
| 123 | next.ServeHTTP(w, r) |
| 124 | }) |
| 125 | } |
no test coverage detected