mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
24w21a
This commit is contained in:
parent
2a5570a447
commit
6f67f6f5b4
9 changed files with 72 additions and 5 deletions
12
main.go
12
main.go
|
|
@ -5,12 +5,14 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"ghproxy/api"
|
||||
"ghproxy/auth"
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
"ghproxy/proxy"
|
||||
"ghproxy/rate"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
|
@ -20,6 +22,7 @@ var (
|
|||
router *gin.Engine
|
||||
configfile = "/data/ghproxy/config/config.toml"
|
||||
cfgfile string
|
||||
limiter *rate.RateLimiter
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -62,6 +65,13 @@ func setupApi(cfg *config.Config, router *gin.Engine) {
|
|||
api.InitHandleRouter(cfg, router)
|
||||
}
|
||||
|
||||
func setupRateLimit(cfg *config.Config) {
|
||||
if cfg.RateLimit.Enabled {
|
||||
limiter = rate.New(cfg.RateLimit.RatePerMinute, cfg.RateLimit.Burst, 1*time.Minute)
|
||||
logInfo("Rate Limit Loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
readFlag()
|
||||
flag.Parse()
|
||||
|
|
@ -92,7 +102,7 @@ func init() {
|
|||
}
|
||||
|
||||
router.NoRoute(func(c *gin.Context) {
|
||||
proxy.NoRouteHandler(cfg)(c)
|
||||
proxy.NoRouteHandler(cfg, limiter)(c)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue