]> 127.0.0.1 Git - front/.git/commitdiff
1 v0.1.20250318071520
authorqydysky <qydysky@foxmail.com>
Tue, 18 Mar 2025 07:13:51 +0000 (07:13 +0000)
committerGitHub <noreply@github.com>
Tue, 18 Mar 2025 07:13:51 +0000 (07:13 +0000)
README.md
config.go

index 38931541f2a396f107f6829a58c01d07767aa371..c950cedf927877555f42c803547018734eccb794 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -74,6 +74,7 @@ config:
 
 - *addr*: string 监听端口 例:`0.0.0.0:8081`
 - *matchRule*: string 匹配规则,默认`prefix`。 `prefix`:当未匹配到时,返回最近的/匹配, `all`:当未匹配到时,返回404
+- reqIdLoop: int 请求id环大小,用于日志识别请求,默认`1000`
 - *copyBlocks*: int 转发的块数量,默认`1000`
 - *retryBlocks*: {} 重试, 当停用时,分配仅进行一次。当所有块都在使用中时,跳过。当请求没有`Content-Length`时,跳过。
     - *size*: string 重试的块大小,默认`1M`
index 7f8ada68a8431c8b67788437df210eff19db3b05..80bdf836c9c3196adc53fa51a710ee4898cc434d 100755 (executable)
--- a/config.go
+++ b/config.go
@@ -47,7 +47,8 @@ type Config struct {
        routeMap sync.Map `json:"-"`
        Routes   []Route  `json:"routes"`
 
-       reqId atomic.Int64 `json:"-"`
+       ReqIdLoop int          `json:"reqIdLoop"`
+       reqId     atomic.Int64 `json:"-"`
 }
 
 func (t *Config) Run(ctx context.Context, logger Logger) {
@@ -70,6 +71,9 @@ func (t *Config) Run(ctx context.Context, logger Logger) {
                        }
                }
        }
+       if t.ReqIdLoop == 0 {
+               t.ReqIdLoop = 1000
+       }
        if t.BlocksI == nil {
                if t.CopyBlocks == 0 {
                        t.CopyBlocks = 1000
@@ -142,7 +146,11 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) {
 
                for _, routePath := range route.Path {
                        t.routeP.Store(routePath, func(w http.ResponseWriter, r *http.Request) {
+
                                reqId := t.reqId.Add(1)
+                               if reqId >= int64(t.ReqIdLoop) {
+                                       t.reqId.Store(0)
+                               }
 
                                if len(r.RequestURI) > 8000 {
                                        logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrUriTooLong))