-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (69 loc) · 2.21 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
75
76
77
78
79
80
package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/khu-dev/khumu-club/adapter/slack"
"github.com/khu-dev/khumu-club/config"
"github.com/khu-dev/khumu-club/http"
"github.com/khu-dev/khumu-club/repository"
"github.com/khu-dev/khumu-club/service"
log "github.com/sirupsen/logrus"
"math/rand"
"runtime"
"time"
)
func init() {
rand.Seed(time.Now().Unix())
log.SetReportCaller(true)
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
DisableQuote: true,
ForceColors: true,
// line을 깔끔하게 보여줌.
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
//filename := strings.Replace(f.File, workingDir + "/", "", -1)
filename := f.File
return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
},
FullTimestamp: true,
TimestampFormat: "2006/01/03 15:04:05",
})
}
func main() {
// Connected with database
client := repository.Connect()
slackAdapter := slack.NewSlackAdapter(config.Config.Slack.Token, config.Config.Slack.Channel)
clubService := &service.ClubService{DB: client, SlackAdapter: slackAdapter}
clubHandler := &http.ClubHandler{ClubService: clubService}
// Create fiber app
app := fiber.New(fiber.Config{})
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
}))
// Middleware
app.Use(recover.New())
app.Use(logger.New())
// JWT Middleware
app.Use(http.NewJWTMiddleware())
app.Get("/healthz", func(ctx *fiber.Ctx) error {
return ctx.SendString("healthy")
})
// Create a /api/v1 endpoint
api := app.Group("/api")
// Bind handlers
api.Post("/clubs", clubHandler.CreateClub)
api.Get("/clubs", clubHandler.ListClubs)
api.Post("/clubs/add-request", clubHandler.ClubAddRequest)
api.Post("/clubs/modify-request", clubHandler.ClubModifyRequest)
api.Get("/club-categories", clubHandler.ListCategories)
//v1.Post("/users", handlers.UserCreate)
// Setup static files
//app.Static("/", "./static/public")
// Handle not founds
app.Use(http.NotFound)
// Listen on port 3000
log.Fatal(app.Listen(fmt.Sprintf("0.0.0.0:%s", config.Config.Port))) // go run app.go -port=:3000
}