Update go cli (#13717)

### What problem does this PR solve?

Go cli

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-03-24 20:08:36 +08:00
committed by GitHub
parent d84b688b91
commit b308cd3a02
28 changed files with 3239 additions and 955 deletions

View File

@ -138,3 +138,29 @@ func GenerateSecretKey() (string, error) {
func GenerateToken() string {
return strings.ReplaceAll(uuid.New().String(), "-", "")
}
// GenerateAPIToken generates a secure random access key
// Equivalent to Python's generate_confirmation_token():
// return "ragflow-" + secrets.token_urlsafe(32)
func GenerateAPIToken() string {
// Generate 32 random bytes
bytes := make([]byte, 32)
if _, err := rand.Read(bytes); err != nil {
// Fallback to UUID if random generation fails
return "ragflow-" + strings.ReplaceAll(uuid.New().String(), "-", "")
}
// Use URL-safe base64 encoding (same as Python's token_urlsafe)
return "ragflow-" + base64.RawURLEncoding.EncodeToString(bytes)
}
// GenerateBetaAPIToken generates a beta access key
// Equivalent to Python's: generate_confirmation_token().replace("ragflow-", "")[:32]
func GenerateBetaAPIToken(accessKey string) string {
// Remove "ragflow-" prefix
withoutPrefix := strings.TrimPrefix(accessKey, "ragflow-")
// Take first 32 characters
if len(withoutPrefix) > 32 {
return withoutPrefix[:32]
}
return withoutPrefix
}