-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
74 lines (66 loc) · 1.38 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
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"os"
"github.com/traPtitech/Jomon/model"
"github.com/traPtitech/Jomon/router"
"github.com/traPtitech/Jomon/storage"
"go.uber.org/zap"
)
func main() {
// Setup ent client
client, err := model.SetupEntClient()
if err != nil {
panic(err)
}
defer client.Close()
// Setup storage
var strg storage.Storage
if os.Getenv("IS_DEBUG_MODE") != "" {
strg, err = storage.NewLocalStorage(os.Getenv("UPLOAD_DIR"))
if err != nil {
panic(err)
}
} else {
strg, err = storage.NewSwiftStorage(
os.Getenv("OS_CONTAINER"),
os.Getenv("OS_USERNAME"),
os.Getenv("OS_PASSWORD"),
os.Getenv("OS_TENANT_NAME"),
os.Getenv("OS_TENANT_ID"),
os.Getenv("OS_AUTH_URL"),
)
if err != nil {
panic(err)
}
}
// Setup repository
repo := model.NewEntRepository(client, strg)
// Setup server
var logger *zap.Logger
if os.Getenv("IS_DEBUG_MODE") != "" {
logger, err = zap.NewDevelopment()
} else {
logger, err = zap.NewProduction()
}
defer func() {
if err := logger.Sync(); err != nil {
panic(err)
}
}()
if err != nil {
panic(err)
}
handlers := router.Handlers{
Repository: repo,
Storage: strg,
Logger: logger,
SessionName: "session",
}
server := router.NewServer(handlers)
port := os.Getenv("PORT")
if port == "" {
port = "1323"
}
// Start server
logger.Fatal("failed to start server", zap.Error(server.Start(":"+port)))
}