-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (36 loc) · 892 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
40
41
42
43
44
45
46
47
48
49
package main
import (
"flag"
"log"
"net/http"
"vms/config"
"vms/routes/v1"
"github.com/rs/cors"
"github.com/spf13/viper"
)
func init() {
//environment flag parser
environment := flag.String("env", "dev", "the environment in which the application should run")
flag.Parse()
config.LoadConfig()
switch *environment {
case "prod":
viper.Set("env", "prod")
case "dev":
viper.Set("env", "dev")
}
log.Printf("%s environment started", viper.Get("env"))
}
func main() {
env := viper.GetString("env")
port := viper.GetString(env + ".port")
// APPLY MIDDLEWARES
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowCredentials: true,
AllowedHeaders: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
})
log.Printf("server running at %s", port)
http.ListenAndServe(":"+port, c.Handler(routes.Router()))
}