forked from NikSchaefer/gofiber-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (52 loc) · 1.47 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
59
60
61
package main
import (
"log"
"os"
"github.com/NikSchaefer/go-fiber/database"
"github.com/NikSchaefer/go-fiber/router"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
)
func getenv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
}
func main() {
godotenv.Load()
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: "*", // comma string format e.g. "localhost, nikschaefer.tech"
AllowHeaders: "Origin, Content-Type, Accept",
}))
database.ConnectDB()
router.Initalize(app)
log.Fatal(app.Listen(":" + getenv("PORT", "3000")))
}
/*
ENV Variables:
will auto set to 3000 if not set
PORT=3000
this should be a connection string or url
DATABASE_URL="host=localhost port=5432 user=postgres password= dbname= sslmode=disable"
**
Docker Command for Postgres database:
docker run --name database -d -p 5432:5432 -e POSTGRES_PASSWORD=password postgres:alpine
DB_URL Variable for docker database
DATABASE_URL="host=localhost port=5432 user=postgres password=password dbname=postgres sslmode=disable"
**
Docker build base image in first stage for development
docker build --target build -t base .
**
run dev container
docker run -p 3000:3000 --mount type=bind,source="C:\Users\schaefer\go\src\fiber",target=/go/src/app --name fiber -td base
**
rebuild and run package
docker exec -it web go run main.go
**
stop and remove container
docker stop fiber; docker rm fiber
*/