-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (33 loc) · 1.04 KB
/
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
40
41
42
43
44
package main
import (
"dumbmerch/database"
"dumbmerch/pkg/mysql"
"dumbmerch/routes"
"fmt"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
func main() {
// env
errEnv := godotenv.Load()
if errEnv != nil {
panic("Failed to load env file")
}
// initial DB
mysql.DatabaseInit()
// run migration
database.RunMigration()
r := mux.NewRouter()
routes.RouteInit(r.PathPrefix("/api/v1").Subrouter())
//path file
r.PathPrefix("/uploads").Handler(http.StripPrefix("/uploads/", http.FileServer(http.Dir("./uploads"))))
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{"*"})
var port = os.Getenv("PORT")
fmt.Println("server running localhost:"+port)
http.ListenAndServe(":"+port, handlers.CORS(AllowedHeaders, AllowedMethods, AllowedOrigins)(r))
}