forked from osuripple/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (77 loc) · 1.92 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
94
package main
import (
"fmt"
"log"
"strings"
"syscall"
"zxq.co/ripple/agplwarning"
"zxq.co/ripple/rippleapi/app"
"zxq.co/ripple/rippleapi/beatmapget"
"zxq.co/ripple/rippleapi/common"
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"
)
// GitHash is the git hash of the application. Do not edit. This is
// automatically set using -ldflags during build time.
var GitHash string
func init() {
log.SetFlags(log.Ltime)
log.SetPrefix(fmt.Sprintf("%d|", syscall.Getpid()))
common.GitHash = GitHash
common.Version = version
}
var db *sqlx.DB
func main() {
err := agplwarning.Warn("ripple", "Ripple API")
if err != nil {
fmt.Println(err)
}
fmt.Print("Ripple API ", version)
if GitHash != "" {
fmt.Print("; git commit hash: ", GitHash)
}
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",
}