-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
64 lines (51 loc) · 1.16 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
package main
import (
"log"
"os"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
)
func backgroundTask() {
for {
time.Sleep(15 * time.Minute)
getRecentsCommits()
}
}
func main() {
// Load dotenv
if err := godotenv.Load(); err != nil {
log.Fatal("No .env file found!")
}
discordToken = os.Getenv("DISCORD_TOKEN")
discordStatusChannel = os.Getenv("DISCORD_STATUS_CHANNEL")
discordUpdateChannel = os.Getenv("DISCORD_UPDATES_CHANNEL")
// get recent commits
getRecentsCommits()
// start Discord bot
go startDiscordBot()
// start background task
go backgroundTask()
// initialize fiber app
app := fiber.New()
app.Use(cors.New())
// root endpoint
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("online")
})
// status endpoint
app.Get("/status", func(c *fiber.Ctx) error {
return c.JSON(currentStatus)
})
// latest updates endpoint
app.Get("/updates", func(c *fiber.Ctx) error {
return c.JSON(currentUpdate)
})
// recent commits endpoint
app.Get("/commits", func(c *fiber.Ctx) error {
return c.JSON(recentCommits)
})
// start fiber app
app.Listen(":3000")
}