arikawa/api/rate/majors.go

42 lines
679 B
Go
Raw Normal View History

2020-01-08 07:10:37 +00:00
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
}