-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (56 loc) · 1.71 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
package main
import (
"log"
"net/http"
"github.com/Bendimester23/go-auth-server/db"
"github.com/Bendimester23/go-auth-server/routes"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/spf13/viper"
)
func loadConfig() {
viper.AddConfigPath("/etc/skyvillage/auth")
viper.AddConfigPath(".")
viper.SetDefault("Listen", ":8080")
viper.SetDefault("StaticUrl", "http://localhost:8080/textures")
viper.SetConfigName("config")
viper.SetConfigType("json")
if err := viper.ReadInConfig(); err != nil {
panic(err)
}
}
func main() {
log.Println("Starting...")
app := fiber.New()
app.Use(logger.New())
app.Use(cors.New())
db.Connect()
defer db.Disconnect()
loadConfig()
setupRoutes(app)
if err := app.Listen(viper.GetString("Listen")); err != nil {
panic(err)
}
}
func setupRoutes(app *fiber.App) {
auth := app.Group("/auth")
auth.Post("/authenticate", routes.HandleAuth_Authenticate)
auth.Post("/refresh", routes.HandleAuth_Refresh)
auth.Post("/validate", routes.HandleAuth_Validate)
auth.Post("/signout", routes.HandleAuth_SignOut)
auth.Post("/invalidate", routes.HandleAuth_Invalidate)
session := app.Group("/session/minecraft")
session.Post("/join", routes.HandleSession_Join)
session.Get("/hasJoined", routes.HandleSession_HasJoined)
session.Get("/profile/:uuid", routes.HandleSession_UuidToProfile)
api := app.Group("/api")
api.Get("/player/attributes", routes.HandleApi_Attributes)
app.Use("/textures", filesystem.New(filesystem.Config{
Root: http.Dir("./static"),
NotFoundFile: "skins/steve.png",
MaxAge: 3600,
Browse: false,
}))
}