mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 16:21:11 +08:00
24w21b
This commit is contained in:
parent
1eed79463d
commit
3c162bf9d7
6 changed files with 89 additions and 15 deletions
26
api/api.go
26
api/api.go
|
|
@ -13,7 +13,6 @@ var (
|
|||
cfg *config.Config
|
||||
)
|
||||
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
logInfo = logger.LogInfo
|
||||
|
|
@ -21,8 +20,7 @@ var (
|
|||
logError = logger.LogError
|
||||
)
|
||||
|
||||
func InitHandleRouter(cfg *config.Config, router *gin.Engine) {
|
||||
// 设置路由
|
||||
func InitHandleRouter(cfg *config.Config, router *gin.Engine, version string) {
|
||||
apiRouter := router.Group("api")
|
||||
{
|
||||
apiRouter.GET("/size_limit", func(c *gin.Context) {
|
||||
|
|
@ -40,6 +38,12 @@ func InitHandleRouter(cfg *config.Config, router *gin.Engine) {
|
|||
apiRouter.GET("/healthcheck", func(c *gin.Context) {
|
||||
HealthcheckHandler(c)
|
||||
})
|
||||
apiRouter.GET("/version", func(c *gin.Context) {
|
||||
VersionHandler(c, version)
|
||||
})
|
||||
apiRouter.GET("/rate_limit/status", func(c *gin.Context) {
|
||||
RateLimitStatusHandler(c, cfg)
|
||||
})
|
||||
}
|
||||
logInfo("API router Init success")
|
||||
}
|
||||
|
|
@ -84,3 +88,19 @@ func HealthcheckHandler(c *gin.Context) {
|
|||
"Status": "OK",
|
||||
})
|
||||
}
|
||||
|
||||
func VersionHandler(c *gin.Context, version string) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Version": version,
|
||||
})
|
||||
}
|
||||
|
||||
func RateLimitStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"RateLimit": cfg.RateLimit.Enabled,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue