增加${requestId}变量

This commit is contained in:
GoEdgeLab
2021-12-02 11:30:47 +08:00
parent dab6efb424
commit cf4d80bd0c
8 changed files with 101 additions and 25 deletions

View File

@@ -3,9 +3,12 @@ package nodes
import (
"crypto/rand"
"fmt"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"io"
"strconv"
"strings"
"sync/atomic"
)
// 分解Range
@@ -125,3 +128,18 @@ func httpRequestGenBoundary() string {
}
return fmt.Sprintf("%x", buf[:])
}
// 生成请求ID
var httpRequestTimestamp int64
var httpRequestId int32 = 1_000_000
func httpRequestNextId() string {
var unixTime = utils.UnixTimeMilli()
if unixTime > httpRequestTimestamp {
atomic.StoreInt32(&httpRequestId, 1_000_000)
httpRequestTimestamp = unixTime
}
// timestamp + requestId + nodeId
return strconv.FormatInt(unixTime, 10) + strconv.Itoa(int(atomic.AddInt32(&httpRequestId, 1))) + teaconst.NodeIdString
}