-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
102 lines (91 loc) · 3.19 KB
/
main.go
File metadata and controls
102 lines (91 loc) · 3.19 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"OctaneServer/config"
"OctaneServer/data"
"OctaneServer/handlers"
"OctaneServer/middleware"
"net/http"
"os"
"time"
_ "OctaneServer/cron"
_ "OctaneServer/docs"
"github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/etag"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/monitor"
"github.com/gofiber/fiber/v2/middleware/pprof"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/swagger"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
if config.CurrentConfig.Debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
log.Info().Msg(config.Msg[config.CurrentConfig.Lang].Console.Starting)
}
// @title OctaneServer
// @version v1
// @description Server-side api of the Octane.
// @contact.name GitHub
// @contact.url https://github.com/Team-Kamo/server
// @BasePath /api/v1
// @securityDefinitions.apikey X-Octane-API-Token
// @in header
// @name X-Octane-API-Token
func main() {
limit := 0
if config.CurrentConfig.BodyLimit < 0 {
limit = -1
} else {
limit = config.CurrentConfig.BodyLimit * 1024 * 1024
}
app := fiber.New(fiber.Config{
AppName: "octane",
ServerHeader: "OctaneServer/v1",
Prefork: true,
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
BodyLimit: limit,
})
if config.CurrentConfig.Debug {
app.Use(pprof.New())
app.Get("/metrics", monitor.New(monitor.Config{Title: "Metrics"}))
}
app.Use(compress.New())
app.Use(recover.New())
app.Use(etag.New())
app.Use(middleware.New())
app.Use(logger.New(logger.Config{Output: log.Logger, Format: config.CurrentConfig.LogFormat}))
app.Use(config.CurrentConfig.Root+"uploads", filesystem.New(filesystem.Config{
Root: http.Dir("./uploads"),
}))
app.Use(limiter.New(limiter.Config{
Max: 20,
Expiration: 10 * time.Second,
}))
app.Get("/swagger/*", swagger.HandlerDefault)
app.Get(config.CurrentConfig.Root+handlers.Health, handlers.HealthGet)
app.Post(config.CurrentConfig.Root+handlers.Room, handlers.RoomPost)
app.Get(config.CurrentConfig.Root+handlers.Status, handlers.StatusGet)
app.Put(config.CurrentConfig.Root+handlers.Status, handlers.StatusPut)
app.Delete(config.CurrentConfig.Root+handlers.Status, handlers.StatusDelete)
app.Get(config.CurrentConfig.Root+handlers.Content, handlers.ContentGet)
app.Put(config.CurrentConfig.Root+handlers.Content, handlers.ContentPut)
app.Delete(config.CurrentConfig.Root+handlers.Content, handlers.ContentDelete)
app.Get(config.CurrentConfig.Root+handlers.RoomID, handlers.RoomIDGet)
app.Post(config.CurrentConfig.Root+handlers.RoomID, handlers.RoomIdPost)
app.Delete(config.CurrentConfig.Root+handlers.RoomID, handlers.RoomIDDelete)
defer func() {
data.Close()
}()
log.Fatal().Err(app.Listen(":" + config.CurrentConfig.Port)).Msg(config.Msg[config.CurrentConfig.Lang].Console.HandlerExit)
}