production runtime and mock removal
This commit is contained in:
1 parent
2ef3da7af5
commit
6480e503eb
55 files changed
+581
-540
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
||||
@@ -301,7 +302,18 @@ func (h *billingHandler) authorize(w http.ResponseWriter, r *http.Request, requi
|
||||
}
|
||||
func decodeJSON(r *http.Request, value any) { _ = json.NewDecoder(r.Body).Decode(value) }
|
||||
func billingString(value any) string { text, _ := value.(string); return strings.TrimSpace(text) }
|
||||
func numberValue(value any) float64 { number, _ := value.(float64); return number }
|
||||
func numberValue(value any) float64 {
|
||||
switch number := value.(type) {
|
||||
case float64:
|
||||
return number
|
||||
case string:
|
||||
parsed, err := strconv.ParseFloat(strings.TrimSpace(number), 64)
|
||||
if err == nil && !math.IsNaN(parsed) && !math.IsInf(parsed, 0) {
|
||||
return parsed
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func first(value, fallback string) string {
|
||||
if value != "" {
|
||||
return value
|
||||
@@ -326,6 +338,10 @@ func writeAuthError(w http.ResponseWriter, err error) {
|
||||
}
|
||||
func writeDomainError(w http.ResponseWriter, err error) {
|
||||
status := billing.HTTPStatus(err)
|
||||
if status == http.StatusServiceUnavailable {
|
||||
writeAPIError(w, status, "计费服务暂不可用,请联系管理员。")
|
||||
return
|
||||
}
|
||||
if status >= 500 {
|
||||
writeAPIError(w, 500, "服务器内部错误。")
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user