Files
xk-hy-transit-go/internal/fileauth/b64_config.go
2026-05-28 16:39:51 +08:00

43 lines
946 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package fileauth
import (
"encoding/base64"
"strings"
)
// B64 编码模式padded=URL-safe 含 =文档样例raw=无填充(联调可切换)。
const (
B64ModePadded = "padded"
B64ModeRaw = "raw"
)
var fileAuthB64Mode = B64ModePadded
// SetB64Mode 设置全局 URL-safe Base64 模式(由 config.FILEAUTH_B64 注入)。
func SetB64Mode(mode string) {
m := strings.ToLower(strings.TrimSpace(mode))
if m == B64ModeRaw {
fileAuthB64Mode = B64ModeRaw
return
}
fileAuthB64Mode = B64ModePadded
}
// B64Mode 返回当前 Base64 模式。
func B64Mode() string { return fileAuthB64Mode }
func encodeURLSafe(data []byte) string {
if fileAuthB64Mode == B64ModeRaw {
return base64RawURL(data)
}
return base64URLPadded(data)
}
func base64URLPadded(data []byte) string {
return base64.URLEncoding.EncodeToString(data)
}
func base64RawURL(data []byte) string {
return base64.RawURLEncoding.EncodeToString(data)
}