mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 16:21:11 +08:00
4.0.0-beta.0
This commit is contained in:
parent
91c3ad7fd8
commit
a4d324a361
38 changed files with 497 additions and 1428 deletions
108
api/api.go
108
api/api.go
|
|
@ -1,95 +1,85 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ghproxy/config"
|
||||
"ghproxy/middleware/nocache"
|
||||
|
||||
"github.com/WJQSERVER-STUDIO/logger"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
"github.com/infinite-iroha/touka"
|
||||
)
|
||||
|
||||
var (
|
||||
logw = logger.Logw
|
||||
logDump = logger.LogDump
|
||||
logDebug = logger.LogDebug
|
||||
logInfo = logger.LogInfo
|
||||
logWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
func InitHandleRouter(cfg *config.Config, r *server.Hertz, version string) {
|
||||
func InitHandleRouter(cfg *config.Config, r *touka.Engine, version string) {
|
||||
apiRouter := r.Group("/api", nocache.NoCacheMiddleware())
|
||||
{
|
||||
apiRouter.GET("/size_limit", func(ctx context.Context, c *app.RequestContext) {
|
||||
SizeLimitHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/size_limit", func(c *touka.Context) {
|
||||
SizeLimitHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/whitelist/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
WhiteListStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/whitelist/status", func(c *touka.Context) {
|
||||
WhiteListStatusHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/blacklist/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
BlackListStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/blacklist/status", func(c *touka.Context) {
|
||||
BlackListStatusHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/cors/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
CorsStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/cors/status", func(c *touka.Context) {
|
||||
CorsStatusHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/healthcheck", func(ctx context.Context, c *app.RequestContext) {
|
||||
HealthcheckHandler(c, ctx)
|
||||
apiRouter.GET("/healthcheck", func(c *touka.Context) {
|
||||
HealthcheckHandler(c)
|
||||
})
|
||||
apiRouter.GET("/version", func(ctx context.Context, c *app.RequestContext) {
|
||||
VersionHandler(c, ctx, version)
|
||||
apiRouter.GET("/ok", func(c *touka.Context) {
|
||||
HealthcheckHandler(c)
|
||||
})
|
||||
apiRouter.GET("/rate_limit/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
RateLimitStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/version", func(c *touka.Context) {
|
||||
VersionHandler(c, version)
|
||||
})
|
||||
apiRouter.GET("/rate_limit/limit", func(ctx context.Context, c *app.RequestContext) {
|
||||
RateLimitLimitHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/rate_limit/status", func(c *touka.Context) {
|
||||
RateLimitStatusHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/smartgit/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
SmartGitStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/rate_limit/limit", func(c *touka.Context) {
|
||||
RateLimitLimitHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/shell_nest/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
shellNestStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/smartgit/status", func(c *touka.Context) {
|
||||
SmartGitStatusHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/oci_proxy/status", func(ctx context.Context, c *app.RequestContext) {
|
||||
ociProxyStatusHandler(cfg, c, ctx)
|
||||
apiRouter.GET("/shell_nest/status", func(c *touka.Context) {
|
||||
shellNestStatusHandler(cfg, c)
|
||||
})
|
||||
apiRouter.GET("/oci_proxy/status", func(c *touka.Context) {
|
||||
ociProxyStatusHandler(cfg, c)
|
||||
})
|
||||
}
|
||||
logInfo("API router Init success")
|
||||
}
|
||||
|
||||
func SizeLimitHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
func SizeLimitHandler(cfg *config.Config, c *touka.Context) {
|
||||
sizeLimit := cfg.Server.SizeLimit
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"MaxResponseBodySize": sizeLimit,
|
||||
}))
|
||||
}
|
||||
|
||||
func WhiteListStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func WhiteListStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"Whitelist": cfg.Whitelist.Enabled,
|
||||
}))
|
||||
}
|
||||
|
||||
func BlackListStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func BlackListStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"Blacklist": cfg.Blacklist.Enabled,
|
||||
}))
|
||||
}
|
||||
|
||||
func CorsStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func CorsStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"Cors": cfg.Server.Cors,
|
||||
}))
|
||||
}
|
||||
|
||||
func HealthcheckHandler(c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func HealthcheckHandler(c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"Status": "OK",
|
||||
"Repo": "WJQSERVER-STUDIO/GHProxy",
|
||||
|
|
@ -97,8 +87,8 @@ func HealthcheckHandler(c *app.RequestContext, ctx context.Context) {
|
|||
}))
|
||||
}
|
||||
|
||||
func VersionHandler(c *app.RequestContext, ctx context.Context, version string) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func VersionHandler(c *touka.Context, version string) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"Version": version,
|
||||
"Repo": "WJQSERVER-STUDIO/GHProxy",
|
||||
|
|
@ -106,36 +96,36 @@ func VersionHandler(c *app.RequestContext, ctx context.Context, version string)
|
|||
}))
|
||||
}
|
||||
|
||||
func RateLimitStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func RateLimitStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"RateLimit": cfg.RateLimit.Enabled,
|
||||
}))
|
||||
}
|
||||
|
||||
func RateLimitLimitHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func RateLimitLimitHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"RatePerMinute": cfg.RateLimit.RatePerMinute,
|
||||
}))
|
||||
}
|
||||
|
||||
func SmartGitStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func SmartGitStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"enabled": cfg.GitClone.Mode == "cache",
|
||||
}))
|
||||
}
|
||||
|
||||
func shellNestStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func shellNestStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"enabled": cfg.Shell.Editor,
|
||||
}))
|
||||
}
|
||||
|
||||
func ociProxyStatusHandler(cfg *config.Config, c *app.RequestContext, ctx context.Context) {
|
||||
c.Response.Header.Set("Content-Type", "application/json")
|
||||
func ociProxyStatusHandler(cfg *config.Config, c *touka.Context) {
|
||||
c.SetHeader("Content-Type", "application/json")
|
||||
c.JSON(200, (map[string]interface{}{
|
||||
"enabled": cfg.Docker.Enabled,
|
||||
"target": cfg.Docker.Target,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue