-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (44 loc) · 1.04 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
package main
import (
"github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/opentreehole/go-common"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
app := fiber.New(fiber.Config{
ErrorHandler: common.ErrorHandler,
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
DisableStartupMessage: true,
BodyLimit: 128 * 1024 * 1024,
})
app.Use(recover.New(recover.Config{
EnableStackTrace: true,
StackTraceHandler: common.StackTraceHandler,
}))
app.Use(common.MiddlewareGetUserID)
app.Use(common.MiddlewareCustomLogger)
router := app.Group("/api")
router.Get("/upload", GetAuthToken)
router.Post("/json", UploadImage)
go func() {
err := app.Listen(":8000")
if err != nil {
log.Println(err)
}
}()
interrupt := make(chan os.Signal, 1)
// wait for CTRL-C interrupt
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interrupt
// close app
err := app.Shutdown()
if err != nil {
log.Println(err)
}
}