forked from RealistikOsu/RealistikAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (76 loc) · 1.97 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"log"
"strings"
"syscall"
"github.com/RealistikOsu/RealistikAPI/app"
"github.com/RealistikOsu/RealistikAPI/beatmapget"
"github.com/RealistikOsu/RealistikAPI/common"
"zxq.co/ripple/agplwarning"
schiavo "zxq.co/ripple/schiavolib"
// Golint pls dont break balls
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/serenize/snaker"
"gopkg.in/thehowl/go-osuapi.v1"
)
// Version is the git hash of the application. Do not edit. This is
// automatically set using -ldflags during build time.
var Version string
func init() {
log.SetFlags(log.Ltime)
log.SetPrefix(fmt.Sprintf("%d|", syscall.Getpid()))
common.Version = Version
}
var db *sqlx.DB
func main() {
err := agplwarning.Warn("ripple", "The RealistikOsu API")
if err != nil {
fmt.Println(err)
}
fmt.Print("The RealistikOsu API! Because how much more can I break?")
if Version != "" {
fmt.Print("; git commit hash: ", Version)
}
fmt.Println()
conf, halt := common.Load()
if halt {
return
}
schiavo.Prefix = "Ripple API"
if !strings.Contains(conf.DSN, "parseTime=true") {
c := "?"
if strings.Contains(conf.DSN, "?") {
c = "&"
}
conf.DSN += c + "parseTime=true&charset=utf8mb4,utf8&collation=utf8mb4_general_ci"
}
db, err = sqlx.Open(conf.DatabaseType, conf.DSN)
if err != nil {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
db.MapperFunc(func(s string) string {
if x, ok := commonClusterfucks[s]; ok {
return x
}
return snaker.CamelToSnake(s)
})
beatmapget.Client = osuapi.NewClient(conf.OsuAPIKey)
beatmapget.DB = db
engine := app.Start(conf, db)
startuato(engine.Handler)
}
var commonClusterfucks = map[string]string{
"RegisteredOn": "register_datetime",
"UsernameAKA": "username_aka",
"BeatmapMD5": "beatmap_md5",
"Count300": "300_count",
"Count100": "100_count",
"Count50": "50_count",
"CountGeki": "gekis_count",
"CountKatu": "katus_count",
"CountMiss": "misses_count",
"PP": "pp",
}