-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
37 lines (32 loc) · 1.05 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
package main
import (
"github.com/gorilla/handlers"
"github.com/gubesch/go-quiz/migration"
"github.com/gubesch/go-quiz/router"
"github.com/joho/godotenv"
"log"
"net/http"
"os"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Println("No .env file present. Environment not loaded from file")
}
argsWithoutProg := os.Args[1:]
if len(argsWithoutProg) != 0 {
if argsWithoutProg[0] == "--migrate" {
migration.MigrateDatabase()
} else if argsWithoutProg[0] == "--migrate:rollback" {
migration.DropDatabase()
} else if argsWithoutProg[0] == "--migrate:fresh" {
migration.DropDatabase()
migration.MigrateDatabase()
}
} else {
port := os.Getenv("HTTP_PORT")
address := os.Getenv("LISTEN_ADDR")
log.Printf("Starting server on %s:%s", address, port)
log.Fatal(http.ListenAndServe(address+":"+port, handlers.CORS(handlers.AllowedHeaders([]string{"content-type", "username", "password", "Access-Control-Allow-Origin", "Authorization"}), handlers.AllowedMethods([]string{"PUT", "GET", "POST", "DELETE"}))(router.CreateRouter())))
}
}