The Ripple API https://ripple.moe/api/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "strings"
  6. "syscall"
  7. "zxq.co/ripple/agplwarning"
  8. "zxq.co/ripple/rippleapi/app"
  9. "zxq.co/ripple/rippleapi/beatmapget"
  10. "zxq.co/ripple/rippleapi/common"
  11. "zxq.co/ripple/schiavolib"
  12. // Golint pls dont break balls
  13. _ "github.com/go-sql-driver/mysql"
  14. "github.com/jmoiron/sqlx"
  15. "github.com/serenize/snaker"
  16. "gopkg.in/thehowl/go-osuapi.v1"
  17. )
  18. // Version is the git hash of the application. Do not edit. This is
  19. // automatically set using -ldflags during build time.
  20. var Version string
  21. func init() {
  22. log.SetFlags(log.Ltime)
  23. log.SetPrefix(fmt.Sprintf("%d|", syscall.Getpid()))
  24. common.Version = Version
  25. }
  26. var db *sqlx.DB
  27. func main() {
  28. err := agplwarning.Warn("ripple", "Ripple API")
  29. if err != nil {
  30. fmt.Println(err)
  31. }
  32. fmt.Print("Ripple API")
  33. if Version != "" {
  34. fmt.Print("; git commit hash: ", Version)
  35. }
  36. fmt.Println()
  37. conf, halt := common.Load()
  38. if halt {
  39. return
  40. }
  41. schiavo.Prefix = "Ripple API"
  42. if !strings.Contains(conf.DSN, "parseTime=true") {
  43. c := "?"
  44. if strings.Contains(conf.DSN, "?") {
  45. c = "&"
  46. }
  47. conf.DSN += c + "parseTime=true&charset=utf8mb4,utf8&collation=utf8mb4_general_ci"
  48. }
  49. db, err = sqlx.Open(conf.DatabaseType, conf.DSN)
  50. if err != nil {
  51. schiavo.Bunker.Send(err.Error())
  52. log.Fatalln(err)
  53. }
  54. db.MapperFunc(func(s string) string {
  55. if x, ok := commonClusterfucks[s]; ok {
  56. return x
  57. }
  58. return snaker.CamelToSnake(s)
  59. })
  60. beatmapget.Client = osuapi.NewClient(conf.OsuAPIKey)
  61. beatmapget.DB = db
  62. engine := app.Start(conf, db)
  63. startuato(engine.Handler)
  64. }
  65. var commonClusterfucks = map[string]string{
  66. "RegisteredOn": "register_datetime",
  67. "UsernameAKA": "username_aka",
  68. "BeatmapMD5": "beatmap_md5",
  69. "Count300": "300_count",
  70. "Count100": "100_count",
  71. "Count50": "50_count",
  72. "CountGeki": "gekis_count",
  73. "CountKatu": "katus_count",
  74. "CountMiss": "misses_count",
  75. "PP": "pp",
  76. }