-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (63 loc) · 1.25 KB
/
main.go
File metadata and controls
79 lines (63 loc) · 1.25 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"errors"
"io"
"log"
"net/http"
"os"
"path/filepath"
"github.com/joho/godotenv"
"github.com/oddinvictus/pinda/db"
"github.com/oddinvictus/pinda/image"
"github.com/oddinvictus/pinda/notifications"
"github.com/redis/go-redis/v9"
)
func main() {
/**
DOTENV
*/
err := godotenv.Load(filepath.Join(os.Getenv("APP_PATH"), ".env"))
if err != nil {
panic(err)
}
/**
DATABASE
*/
client := db.NewClient()
if err := client.Prisma.Connect(); err != nil {
panic(err)
}
defer func() {
if err := client.Prisma.Disconnect(); err != nil {
panic(err)
}
}()
/**
REDIS
*/
redisURL := os.Getenv("REDIS_URL")
if redisURL == "" {
redisURL = "localhost:6379"
}
rdb := redis.NewClient(&redis.Options{
Addr: redisURL,
Password: "",
DB: 0,
})
image.Init(rdb)
notifications.Init(rdb, client)
/**
HTTP Routing
*/
router := http.NewServeMux()
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Invictus Bier Systeem API")
})
log.Println("Listening on http://127.0.0.1:3000")
err = http.ListenAndServe(":3000", router)
if errors.Is(err, http.ErrServerClosed) {
log.Panicln("server closed")
} else if err != nil {
log.Panicln("error starting server", err)
}
}