-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (29 loc) · 875 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"
"net/http"
"github.com/LucioSchiavoni/go-postgres/db"
"github.com/LucioSchiavoni/go-postgres/models"
"github.com/LucioSchiavoni/go-postgres/routes"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
fmt.Println("Corriendo server de go")
r := mux.NewRouter()
db.DBConnection()
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"})
originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
if isDevelopment() {
db.DB.AutoMigrate(models.User{})
db.DB.AutoMigrate(models.Post{})
}
http.Handle("/", handlers.CORS(headersOk, originsOk, methodsOk)(r))
routes.UserRoutes(r)
routes.PostRoutes(r)
http.ListenAndServe(":3000", nil)
}
func isDevelopment() bool {
return false
}