- 全局替换 ApiKey → APIKey(类型、字段、方法、变量) - 修复所有 initialism 命名(API, SMTP, HTML, URL 等) - 添加所有缺失的包注释 - 修复导出符号的注释格式 主要修改: - ApiKey → APIKey(所有出现的地方) - ApiKeyID → APIKeyID - ApiKeyIDs → APIKeyIDs - TestSmtpConnection → TestSMTPConnection - HtmlURL → HTMLURL - 添加 20+ 个包注释 - 修复 10+ 个导出符号注释格式 验证结果: - ✓ golangci-lint: 0 issues - ✓ 单元测试: 通过 - ✓ 集成测试: 通过
26 lines
629 B
Go
26 lines
629 B
Go
// Package googleapi provides helpers for Google-style API responses.
|
|
package googleapi
|
|
|
|
import "net/http"
|
|
|
|
// HTTPStatusToGoogleStatus maps HTTP status codes to Google-style error status strings.
|
|
func HTTPStatusToGoogleStatus(status int) string {
|
|
switch status {
|
|
case http.StatusBadRequest:
|
|
return "INVALID_ARGUMENT"
|
|
case http.StatusUnauthorized:
|
|
return "UNAUTHENTICATED"
|
|
case http.StatusForbidden:
|
|
return "PERMISSION_DENIED"
|
|
case http.StatusNotFound:
|
|
return "NOT_FOUND"
|
|
case http.StatusTooManyRequests:
|
|
return "RESOURCE_EXHAUSTED"
|
|
default:
|
|
if status >= 500 {
|
|
return "INTERNAL"
|
|
}
|
|
return "UNKNOWN"
|
|
}
|
|
}
|