/
route.go
48 lines (40 loc) · 1.27 KB
/
route.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
package controller
import (
"net/http"
"github.com/ECNU/Open-OAuth2Playground/g"
"github.com/gin-gonic/gin"
)
func Routes(r *gin.Engine) {
r.Static(g.Config().Http.RouteBase+"css/", "front-standalone/dist/css/")
r.Static(g.Config().Http.RouteBase+"js/", "front-standalone/dist/js/")
r.StaticFile(g.Config().Http.RouteBase, "front-standalone/dist/index.html")
r.StaticFile(g.Config().Http.RouteBase+"favicon.ico", "front-standalone/dist/favicon.ico")
r.GET(g.Config().Http.RouteBase+"v1/config", getConfig)
playground := r.Group(g.Config().Http.RouteBase + "v1")
playground.Use(IPLimitCheck)
playground.Use(NoCache())
playground.POST("/oauth2/client_credentials", clientCredentials)
playground.POST("/oauth2/password", passwordMode)
playground.POST("/oauth2/authorization_code", exchangeTokenByCode)
playground.POST("/oauth2/refresh_token", refreshToken)
playground.POST("/api", api)
}
func InitGin(listen string) (httpServer *http.Server) {
if g.Config().Logger.Level == "DEBUG" {
gin.SetMode((gin.DebugMode))
} else {
gin.SetMode(gin.ReleaseMode)
}
r := gin.New()
if g.Config().Logger.Level == "DEBUG" {
r.Use(gin.Logger())
}
r.Use(gin.Recovery())
r.Use(CORS())
Routes(r)
httpServer = &http.Server{
Addr: g.Config().Http.Listen,
Handler: r,
}
return
}