forked from osuthailand/api
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
80 lines (66 loc) · 1.81 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
package main
import (
"fmt"
"log"
"syscall"
"github.com/RealistikOsu/RealistikAPI/app"
"github.com/RealistikOsu/RealistikAPI/beatmapget"
"github.com/RealistikOsu/RealistikAPI/common"
"github.com/valyala/fasthttp"
// 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()))
}
func main() {
fmt.Print("The RealistikOsu API! Because how much more can I break?")
if Version != "" {
fmt.Print("; git commit hash: ", Version)
}
fmt.Println()
settings := common.LoadSettings()
dns := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true&charset=utf8mb4,utf8&collation=utf8mb4_general_ci",
settings.DB_USER,
settings.DB_PASS,
settings.DB_HOST,
settings.DB_PORT,
settings.DB_NAME,
)
db, err := sqlx.Open(settings.DB_SCHEME, dns)
if err != nil {
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(settings.OSU_API_KEY)
beatmapget.DB = db
engine := app.Start(db)
err = fasthttp.ListenAndServe(fmt.Sprintf(":%d", settings.APP_PORT), engine.Handler)
if err != nil {
log.Fatalln(err)
}
}
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",
}