-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (49 loc) · 1.12 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
package main
import (
"errors"
"log"
"github.com/gofiber/fiber/v2"
"github.com/hackagotchi/hkgi/database"
"github.com/hackagotchi/hkgi/internal"
"github.com/hackagotchi/hkgi/internal/game"
"github.com/hackagotchi/hkgi/internal/state"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load(".env")
state.InitState()
if err != nil {
log.Fatal(err)
}
app := fiber.New(fiber.Config{
ErrorHandler: func(c *fiber.Ctx, err error) error {
// Status code defaults to 500
code := fiber.StatusInternalServerError
// Retrieve the custom status code if it's a *fiber.Error
var tmp *fiber.Error
e := fiber.Error{}
if errors.As(err, &tmp) {
code = tmp.Code
} else {
e.Code = code
}
e.Message = err.Error()
// Send custom error page
return c.Status(code).SendString(e.Message)
// Return from handler
return nil
},
})
internal.SetupRoutes(app)
database.ConnectDB()
app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(&fiber.Map{"data": "Hello from Fiber!"})
})
go func() {
err := game.RunTick()
if err != nil {
log.Fatal(err)
}
}()
app.Listen(":6000")
}