ripple-api/app/start.go

91 lines
3.3 KiB
Go
Raw Normal View History

2016-04-03 17:59:27 +00:00
package app
import (
"database/sql"
2016-04-19 14:07:27 +00:00
"git.zxq.co/ripple/rippleapi/app/internals"
"git.zxq.co/ripple/rippleapi/app/peppy"
2016-04-19 14:07:27 +00:00
"git.zxq.co/ripple/rippleapi/app/v1"
"git.zxq.co/ripple/rippleapi/common"
2016-04-03 17:59:27 +00:00
"github.com/gin-gonic/contrib/gzip"
"github.com/gin-gonic/gin"
)
var db *sql.DB
2016-04-03 17:59:27 +00:00
// Start begins taking HTTP connections.
func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
db = dbO
2016-04-03 17:59:27 +00:00
r := gin.Default()
2016-04-07 09:38:57 +00:00
r.Use(gzip.Gzip(gzip.DefaultCompression), ErrorHandler())
2016-04-03 17:59:27 +00:00
api := r.Group("/api")
{
gv1 := api.Group("/v1")
{
gv1.POST("/tokens/new", Method(v1.TokenNewPOST))
2016-04-05 20:22:13 +00:00
2016-04-03 20:31:41 +00:00
// Auth-free API endpoints
gv1.GET("/ping", Method(v1.PingGET))
gv1.GET("/surprise_me", Method(v1.SurpriseMeGET))
gv1.GET("/privileges", Method(v1.PrivilegesGET))
2016-06-13 20:40:01 +00:00
gv1.GET("/doc", Method(v1.DocGET))
gv1.GET("/doc/content", Method(v1.DocContentGET))
gv1.GET("/doc/rules", Method(v1.DocRulesGET))
2016-04-03 20:31:41 +00:00
// Read privilege required
gv1.GET("/users", Method(v1.UsersGET, common.PrivilegeRead))
gv1.GET("/users/self", Method(v1.UserSelfGET, common.PrivilegeRead))
gv1.GET("/users/whatid", Method(v1.UserWhatsTheIDGET, common.PrivilegeRead))
gv1.GET("/users/full", Method(v1.UserFullGET, common.PrivilegeRead))
gv1.GET("/users/userpage", Method(v1.UserUserpageGET, common.PrivilegeRead))
gv1.GET("/users/lookup", Method(v1.UserLookupGET, common.PrivilegeRead))
2016-05-19 15:15:17 +00:00
gv1.GET("/users/scores/best", Method(v1.UserScoresBestGET, common.PrivilegeRead))
2016-05-19 15:31:49 +00:00
gv1.GET("/users/scores/recent", Method(v1.UserScoresRecentGET, common.PrivilegeRead))
gv1.GET("/badges", Method(v1.BadgesGET, common.PrivilegeRead))
2016-06-08 17:55:52 +00:00
gv1.GET("/beatmaps", Method(v1.BeatmapGET, common.PrivilegeRead))
2016-06-14 07:37:11 +00:00
gv1.GET("/leaderboard", Method(v1.LeaderboardGET, common.PrivilegeRead))
2016-04-07 09:20:35 +00:00
// ReadConfidential privilege required
gv1.GET("/friends", Method(v1.FriendsGET, common.PrivilegeReadConfidential))
gv1.GET("/friends/with", Method(v1.FriendsWithGET, common.PrivilegeReadConfidential))
2016-04-07 17:32:48 +00:00
// Write privilege required
gv1.GET("/friends/add", Method(v1.FriendsAddGET, common.PrivilegeWrite))
gv1.GET("/friends/del", Method(v1.FriendsDelGET, common.PrivilegeWrite))
2016-04-27 18:03:06 +00:00
// Admin: beatmap
gv1.POST("/beatmaps/set_status", Method(v1.BeatmapSetStatusPOST, common.PrivilegeBeatmap))
gv1.GET("/beatmaps/ranked_frozen_full", Method(v1.BeatmapRankedFrozenFullGET, common.PrivilegeBeatmap))
2016-04-27 18:03:06 +00:00
2016-04-12 19:41:08 +00:00
// Admin: user managing
gv1.POST("/users/manage/set_allowed", Method(v1.UserManageSetAllowedPOST, common.PrivilegeManageUser))
2016-04-12 19:41:08 +00:00
2016-04-07 17:32:48 +00:00
// M E T A
// E T "wow thats so meta"
// T E -- the one who said "wow thats so meta"
2016-04-07 17:32:48 +00:00
// A T E M
gv1.GET("/meta/restart", Method(v1.MetaRestartGET, common.PrivilegeAPIMeta))
gv1.GET("/meta/kill", Method(v1.MetaKillGET, common.PrivilegeAPIMeta))
gv1.GET("/meta/up_since", Method(v1.MetaUpSinceGET, common.PrivilegeAPIMeta))
gv1.GET("/meta/update", Method(v1.MetaUpdateGET, common.PrivilegeAPIMeta))
2016-04-03 17:59:27 +00:00
}
api.GET("/status", internals.Status)
// peppyapi
api.GET("/get_user", PeppyMethod(peppy.GetUser))
api.GET("/get_match", PeppyMethod(peppy.GetMatch))
api.GET("/get_user_recent", PeppyMethod(peppy.GetUserRecent))
api.GET("/get_user_best", PeppyMethod(peppy.GetUserBest))
2016-04-03 17:59:27 +00:00
}
r.NoRoute(v1.Handle404)
2016-04-07 17:32:48 +00:00
return r
/*if conf.Unix {
2016-04-03 17:59:27 +00:00
panic(r.RunUnix(conf.ListenTo))
}
2016-04-07 17:32:48 +00:00
panic(r.Run(conf.ListenTo))*/
2016-04-03 17:59:27 +00:00
}