package shared import "fmt" // MaskAPIKey 脱敏 API 密钥,保留前 4 字符. // 精妙之处(CLEVER): 提取为共享函数--6 个 provider 都用同一逻辑, // 原来各自复制,改一个忘另一个就是安全漏洞(比如新 provider 忘记脱敏). func MaskAPIKey(key string) string { if len(key) > 4 { return key[:4] + "****" } if key != "" { return "****" } return "[empty]" } // GoStringWithMaskedKey 生成脱敏的 GoString 输出,用于防止 %#v 泄露 APIKey. func GoStringWithMaskedKey(typeName, apiKey string) string { return fmt.Sprintf("%s{APIKey: %q, ...}", typeName, MaskAPIKey(apiKey)) }