- *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`
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) {
}
}
}
+ if t.ReqIdLoop == 0 {
+ t.ReqIdLoop = 1000
+ }
if t.BlocksI == nil {
if t.CopyBlocks == 0 {
t.CopyBlocks = 1000
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))