ripple-api/main.go

88 lines
1.8 KiB
Go
Raw Normal View History

2016-04-03 17:59:27 +00:00
package main
import (
2016-04-07 17:32:48 +00:00
"fmt"
2016-04-03 17:59:27 +00:00
"log"
2016-07-06 22:20:36 +00:00
"strings"
2016-04-07 17:32:48 +00:00
"syscall"
2016-04-03 17:59:27 +00:00
2017-01-14 17:06:16 +00:00
"zxq.co/ripple/rippleapi/app"
"zxq.co/ripple/rippleapi/beatmapget"
"zxq.co/ripple/rippleapi/common"
"zxq.co/ripple/schiavolib"
2016-04-03 17:59:27 +00:00
// Golint pls dont break balls
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
2017-02-19 17:19:59 +00:00
"github.com/serenize/snaker"
2016-09-06 23:51:23 +00:00
"gopkg.in/thehowl/go-osuapi.v1"
2016-04-03 17:59:27 +00:00
)
2016-06-17 08:34:53 +00:00
// Version is the git hash of the application. Do not edit. This is
// automatically set using -ldflags during build time.
var Version string
2016-04-07 17:32:48 +00:00
func init() {
log.SetFlags(log.Ltime)
log.SetPrefix(fmt.Sprintf("%d|", syscall.Getpid()))
2016-06-17 08:34:53 +00:00
common.Version = Version
2016-04-07 17:32:48 +00:00
}
var db *sqlx.DB
2016-04-03 17:59:27 +00:00
func main() {
2016-06-17 08:34:53 +00:00
fmt.Print("Ripple API")
if Version != "" {
fmt.Print("; git commit hash: ", Version)
}
fmt.Println()
2016-04-03 17:59:27 +00:00
conf, halt := common.Load()
if halt {
return
}
2016-05-22 15:11:07 +00:00
schiavo.Prefix = "Ripple API"
2016-07-06 22:20:36 +00:00
if !strings.Contains(conf.DSN, "parseTime=true") {
c := "?"
if strings.Contains(conf.DSN, "?") {
c = "&"
}
2016-11-20 12:46:44 +00:00
conf.DSN += c + "parseTime=true&charset=utf8mb4,utf8&collation=utf8mb4_general_ci"
2016-07-06 22:20:36 +00:00
}
var err error
db, err = sqlx.Open(conf.DatabaseType, conf.DSN)
2016-04-03 17:59:27 +00:00
if err != nil {
2016-05-22 15:11:07 +00:00
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
2016-04-03 17:59:27 +00:00
}
2016-09-06 23:51:23 +00:00
2017-02-19 17:19:59 +00:00
db.MapperFunc(func(s string) string {
if x, ok := commonClusterfucks[s]; ok {
return x
}
return snaker.CamelToSnake(s)
})
2016-09-06 23:51:23 +00:00
beatmapget.Client = osuapi.NewClient(conf.OsuAPIKey)
beatmapget.DB = db
2016-04-07 17:32:48 +00:00
engine := app.Start(conf, db)
startuato(engine.Handler)
2016-04-03 17:59:27 +00:00
}
2017-02-19 17:19:59 +00:00
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",
}