Mirror Zhanlu client: GLM tool_stream, shared v4 UUID request id, drop chat state:ERROR
build / build (push) Successful in 2m26s
build / build (push) Successful in 2m26s
This commit is contained in:
+20
-1
@@ -2,7 +2,12 @@
|
||||
// avoid divergent same-named copies.
|
||||
package util
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FirstNonEmpty returns the first trimmed-non-empty value, or "" when none of
|
||||
// the values are non-empty. Callers that need a specific fallback for the
|
||||
@@ -15,3 +20,17 @@ func FirstNonEmpty(values ...string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// RandomRequestID returns a random v4 UUID string, matching the format the
|
||||
// Zhanlu plugin sends in the `request` header of every gateway call
|
||||
// (crypto.randomUUID()). Extracted so the login and phone-code paths share
|
||||
// one implementation.
|
||||
func RandomRequestID() string {
|
||||
b := make([]byte, 16)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return fmt.Sprintf("%d", time.Now().UnixNano())
|
||||
}
|
||||
b[6] = (b[6] & 0x0f) | 0x40
|
||||
b[8] = (b[8] & 0x3f) | 0x80
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user