Headers for CORS

Preflight Request

Implement CORS

func setupCorsResponse(w *http.ResponseWriter, req *http.Request) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
(*w).Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
(*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Authorization")
// Register routing for creating customer
route.Handle("/"+APIVersion+"/customers", createUser()).
Methods(http.MethodPost, http.MethodOptions).
Name("Create customer")
func createUser(w http.ResponseWriter, req *http.Request) {
setupCorsResponse(&w, req)
if (*req).Method == "OPTIONS" {

// process the request...

Love to write code and discuss technology | If you explain others is simple words it means you know it very well

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store