2016-04-03 17:59:27 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/contrib/gzip"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/osuripple/api/app/v1"
|
|
|
|
"github.com/osuripple/api/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Start begins taking HTTP connections.
|
2016-04-07 17:32:48 +00:00
|
|
|
func Start(conf common.Conf, db *sql.DB) *gin.Engine {
|
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")
|
|
|
|
{
|
2016-04-05 20:22:13 +00:00
|
|
|
gv1.POST("/token/new", Method(v1.TokenNewPOST, db))
|
|
|
|
|
2016-04-03 20:31:41 +00:00
|
|
|
// Auth-free API endpoints
|
2016-04-04 12:36:37 +00:00
|
|
|
gv1.GET("/ping", Method(v1.PingGET, db))
|
|
|
|
gv1.GET("/surprise_me", Method(v1.SurpriseMeGET, db))
|
2016-04-03 17:59:27 +00:00
|
|
|
gv1.GET("/privileges", Method(v1.PrivilegesGET, db))
|
2016-04-03 20:31:41 +00:00
|
|
|
|
|
|
|
// Read privilege required
|
2016-04-03 21:09:28 +00:00
|
|
|
gv1.GET("/users/id/:id", Method(v1.UserByIDGET, db, common.PrivilegeRead))
|
|
|
|
gv1.GET("/users/name/:name", Method(v1.UserByNameGET, db, common.PrivilegeRead))
|
2016-04-05 20:38:33 +00:00
|
|
|
gv1.GET("/users/self", Method(v1.UserSelfGET, db, common.PrivilegeRead))
|
2016-04-07 09:59:38 +00:00
|
|
|
gv1.GET("/users/whatid/:username", Method(v1.UserWhatsTheIDGET, db, common.PrivilegeRead))
|
2016-04-07 11:47:42 +00:00
|
|
|
gv1.GET("/users/full/:id", Method(v1.UserFullGET, db, common.PrivilegeRead))
|
2016-04-07 12:42:17 +00:00
|
|
|
gv1.GET("/users/userpage/:id", Method(v1.UserUserpageGET, db, common.PrivilegeRead))
|
2016-04-03 20:31:41 +00:00
|
|
|
gv1.GET("/badges", Method(v1.BadgesGET, db, common.PrivilegeRead))
|
|
|
|
gv1.GET("/badges/:id", Method(v1.BadgeByIDGET, db, common.PrivilegeRead))
|
2016-04-07 09:20:35 +00:00
|
|
|
|
|
|
|
// ReadConfidential privilege required
|
|
|
|
gv1.GET("/friends", Method(v1.FriendsGET, db, common.PrivilegeReadConfidential))
|
2016-04-07 10:21:54 +00:00
|
|
|
gv1.GET("/friends/with/:id", Method(v1.FriendsWithGET, db, common.PrivilegeReadConfidential))
|
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 that's so meta"
|
|
|
|
// A T E M
|
|
|
|
gv1.GET("/meta/restart", Method(v1.MetaRestartGET, db, common.PrivilegeAPIMeta))
|
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
|
|
|
}
|