移除被错误提交的测试用exe文件
修复前后端逻辑
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -771,96 +770,6 @@ func decodeStringSlice(raw *string) []string {
|
||||
return filterNonEmptyStrings(strings.Split(*raw, ","))
|
||||
}
|
||||
|
||||
func marshalJSON(value any, fallbackEmptyArray bool) (*string, error) {
|
||||
if value == nil {
|
||||
if fallbackEmptyArray {
|
||||
empty := "[]"
|
||||
return &empty, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if text, ok := value.(string); ok {
|
||||
text = strings.TrimSpace(text)
|
||||
if text == "" {
|
||||
if fallbackEmptyArray {
|
||||
empty := "[]"
|
||||
return &empty, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
if json.Valid([]byte(text)) {
|
||||
return &text, nil
|
||||
}
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
text := string(payload)
|
||||
return &text, nil
|
||||
}
|
||||
|
||||
func stringFromAny(value any) string {
|
||||
switch typed := value.(type) {
|
||||
case string:
|
||||
return typed
|
||||
case json.Number:
|
||||
return typed.String()
|
||||
case float64:
|
||||
return strconv.FormatFloat(typed, 'f', -1, 64)
|
||||
case float32:
|
||||
return strconv.FormatFloat(float64(typed), 'f', -1, 32)
|
||||
case int:
|
||||
return strconv.Itoa(typed)
|
||||
case int64:
|
||||
return strconv.FormatInt(typed, 10)
|
||||
case bool:
|
||||
if typed {
|
||||
return "true"
|
||||
}
|
||||
return "false"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func nullableString(value any) any {
|
||||
text := strings.TrimSpace(stringFromAny(value))
|
||||
if text == "" {
|
||||
return nil
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
func intFromAny(value any) int {
|
||||
switch typed := value.(type) {
|
||||
case int:
|
||||
return typed
|
||||
case int8:
|
||||
return int(typed)
|
||||
case int16:
|
||||
return int(typed)
|
||||
case int32:
|
||||
return int(typed)
|
||||
case int64:
|
||||
return int(typed)
|
||||
case float32:
|
||||
return int(typed)
|
||||
case float64:
|
||||
return int(typed)
|
||||
case json.Number:
|
||||
parsed, _ := typed.Int64()
|
||||
return int(parsed)
|
||||
case string:
|
||||
parsed, _ := strconv.Atoi(strings.TrimSpace(typed))
|
||||
return parsed
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func float32FromAny(value any) (float32, bool) {
|
||||
switch typed := value.(type) {
|
||||
case float32:
|
||||
@@ -891,64 +800,19 @@ func nullableInt(value any) any {
|
||||
}
|
||||
|
||||
func nullableInt64(value any) any {
|
||||
switch typed := value.(type) {
|
||||
case int64:
|
||||
if typed > 0 {
|
||||
return typed
|
||||
}
|
||||
case int:
|
||||
if typed > 0 {
|
||||
return int64(typed)
|
||||
}
|
||||
case float64:
|
||||
if typed > 0 {
|
||||
return int64(typed)
|
||||
}
|
||||
case string:
|
||||
if parsed, err := strconv.ParseInt(strings.TrimSpace(typed), 10, 64); err == nil && parsed > 0 {
|
||||
return parsed
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func boolFromAny(value any) bool {
|
||||
switch typed := value.(type) {
|
||||
case bool:
|
||||
return typed
|
||||
case int:
|
||||
return typed != 0
|
||||
case int64:
|
||||
return typed != 0
|
||||
case float64:
|
||||
return typed != 0
|
||||
case string:
|
||||
text := strings.TrimSpace(strings.ToLower(typed))
|
||||
return text == "1" || text == "true" || text == "yes" || text == "on"
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func stringValue(value *string) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
func intValue(value *int) any {
|
||||
if value == nil {
|
||||
parsed := intFromAny(value)
|
||||
if parsed <= 0 {
|
||||
return nil
|
||||
}
|
||||
return *value
|
||||
return int64(parsed)
|
||||
}
|
||||
|
||||
func int64Value(value *int64) any {
|
||||
if value == nil {
|
||||
func nullableString(value any) any {
|
||||
text := strings.TrimSpace(stringFromAny(value))
|
||||
if text == "" {
|
||||
return nil
|
||||
}
|
||||
return *value
|
||||
return text
|
||||
}
|
||||
|
||||
func filterNonEmptyStrings(values any) []string {
|
||||
@@ -972,23 +836,6 @@ func filterNonEmptyStrings(values any) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func sanitizePositiveIDs(ids []int) []int {
|
||||
unique := make(map[int]struct{}, len(ids))
|
||||
result := make([]int, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id <= 0 {
|
||||
continue
|
||||
}
|
||||
if _, exists := unique[id]; exists {
|
||||
continue
|
||||
}
|
||||
unique[id] = struct{}{}
|
||||
result = append(result, id)
|
||||
}
|
||||
sort.Ints(result)
|
||||
return result
|
||||
}
|
||||
|
||||
func intSliceContains(values []int, target int) bool {
|
||||
for _, value := range values {
|
||||
if value == target {
|
||||
@@ -1007,9 +854,3 @@ func isAllowedRouteAction(action string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func unixTimeValue(value *time.Time) any {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
return value.Unix()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user