-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (29 loc) · 958 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
39
package main
import (
"baharsah/helper/mysql"
"baharsah/migration"
"baharsah/router"
"net/http"
"os"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
// Cors
// Setup allowed Header, Method, and Origin for CORS on this below code ...
var AllowedHeaders = handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"})
var AllowedMethods = handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS", "PATCH", "DELETE"})
var AllowedOrigins = handlers.AllowedOrigins([]string{"*"})
err := godotenv.Load()
if err != nil {
}
mysql.DBInit()
migration.RunMigration()
r := mux.NewRouter()
router.Router(r.PathPrefix("/api/v1").Subrouter())
log.Println("Server Running!")
srverr := http.ListenAndServe(":"+os.Getenv("PORT"), handlers.CORS(AllowedHeaders, AllowedMethods, AllowedOrigins)(r))
log.Println(srverr)
}