pp_projekt/main.go
2019-01-12 22:07:47 +01:00

36 lines
1.1 KiB
Go

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:=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("/query", updateQuery).Methods("PUT", "OPTIONS")
log.Fatal(http.ListenAndServe(":8080", handlers.CORS(alowedHeaders, allowedOrigins, allowedMethods)(router)))
}
func enableCors(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
}