package main import ( "github.com/gorilla/mux" "github.com/gorilla/handlers" "log" "net/http" ) import _"github.com/lib/pq" func main() { alowedHeaders := handlers.AllowedHeaders([]string{"Content-Type"}) allowedOrigins := handlers.AllowedOrigins([]string{"*"}) allowedMethods := handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS", "DELETE", "PUT"}) initDb() defer db.Close() //router := NewRouter() router:=mux.NewRouter() router.HandleFunc("/term/{year}/{month}", getTerms).Methods("GET", "OPTIONS") router.HandleFunc("/term", newTerm).Methods("POST", "OPTIONS") router.HandleFunc("/term", deleteTerm).Methods("DELETE", "OPTIONS") router.HandleFunc("/term", putTerm).Methods("PUT", "OPTIONS") router.HandleFunc("/query", newQuery).Methods("POST", "OPTIONS") router.HandleFunc("/query", getQueryList).Methods("GET", "OPTIONS") router.HandleFunc("/test", postTest).Methods("POST", "OPTIONS") router.HandleFunc("/test", deleteTest).Methods("DELETE", "OPTIONS") log.Fatal(http.ListenAndServe(":8080", handlers.CORS(alowedHeaders, allowedOrigins, allowedMethods)(router))) } func enableCors(w *http.ResponseWriter) { (*w).Header().Set("Access-Control-Allow-Origin", "*") }