-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (32 loc) · 785 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
carsController "main/controllers"
"net/http"
_ "github.com/go-sql-driver/mysql"
"github.com/julienschmidt/httprouter"
"github.com/rs/cors"
)
func main() {
r := httprouter.New()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
},
AllowedHeaders: []string{"*"},
AllowCredentials: false,
})
r.GET("/health", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
fmt.Fprintf(w, "Server is running")
})
r.POST("/createCar", carsController.CreateCar)
r.GET("/getCars", carsController.GetCars)
handler := cors.Handler(r)
port := ":3002"
http.ListenAndServe(port, handler)
}