-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmthandlers.go
58 lines (52 loc) · 1.28 KB
/
rmthandlers.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
package main
import (
"time"
"github.com/gin-gonic/gin"
"golang.org/x/time/rate"
)
type rmtHandler struct {
name string
lclEndpoint string
rmtURL func(c *gin.Context) string
rmtLimit *rate.Limit
}
var (
rmtHandlers = []rmtHandler{
{
name: "osufile",
lclEndpoint: "/api/v1/osufile/:id",
rmtURL: func(c *gin.Context) string {
return "/osu/" + c.Param("id")
},
},
{
name: "userinfo",
lclEndpoint: "/api/v1/users/:user/:mode",
rmtURL: func(c *gin.Context) string {
return "/api/v2/users/" + c.Param("user") + "/" + c.Param("mode")
},
},
{
name: "scorefile",
lclEndpoint: "/api/v1/scorefile/:mode/:score",
rmtURL: func(c *gin.Context) string {
return "/api/v2/scores/" + c.Param("mode") + "/" + c.Param("score") + "/download"
},
rmtLimit: &[]rate.Limit{rate.Every(6 * time.Second)}[0], // Hack to get a pointer
},
{
name: "beatmaps_lookup_checksum",
lclEndpoint: "/api/v1/beatmaps/lookup/s/:checksum",
rmtURL: func(c *gin.Context) string {
return "/api/v2/beatmaps/lookup?checksum=" + c.Param("checksum")
},
},
}
)
func handlersMap() map[string]rmtHandler {
m := make(map[string]rmtHandler)
for _, handler := range rmtHandlers {
m[handler.name] = handler
}
return m
}