1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-19 13:22:54 +00:00
arikawa/api/rate/majors.go

42 lines
679 B
Go

package rate
import (
"strconv"
"strings"
)
// TODO: webhook
var MajorRootPaths = []string{"channels", "guilds"}
func ParseBucketKey(path string) string {
path = strings.SplitN(path, "?", 2)[0]
parts := strings.Split(path, "/")
if len(parts) < 1 {
return path
}
parts = parts[1:] // [0] is just "" since URL
var skip int
for _, part := range MajorRootPaths {
if part == parts[0] {
skip = 2
break
}
}
// we need to remove IDs from these
for ; skip < len(parts); skip++ {
if _, err := strconv.Atoi(parts[skip]); err == nil {
// is a number, DELET
parts[skip] = ""
}
}
// rejoin url
path = strings.Join(parts, "/")
return "/" + path
}