-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (47 loc) · 1.06 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
"github.com/simpleittools/assetapi/database"
"github.com/simpleittools/assetapi/handlers"
"github.com/simpleittools/assetapi/routes"
"log"
"os"
)
func main() {
// Load the environment variables
err := godotenv.Load()
if err != nil {
log.Fatal("cannot find .env file. Please create the .env file")
}
status := os.Getenv("STATUS")
if status == "DEVELOPMENT" {
fmt.Println("We are in DEV")
} else if status == "PRODUCTION" {
fmt.Println("We are in PROD")
} else {
log.Panicln("Invalid Status configuration")
}
PORT := os.Getenv("APIPORT")
app := fiber.New()
database.Conn()
seedDb := os.Getenv("SEEDDB")
switch seedDb {
case "TRUE":
handlers.Seed()
case "FAlSE":
fmt.Println("You are not seeding the DB")
default:
log.Fatal("unable to determine seeding")
}
app.Use(cors.New(cors.Config{
AllowCredentials: true,
}))
routes.APIRoutes(app)
err = app.Listen(PORT)
if err != nil {
log.Fatal(err)
}
}