优化结构

This commit is contained in:
Yvan
2026-08-28 11:10:57 +08:00
parent 5b17f47141
commit 676fa4d952
10 changed files with 91 additions and 80 deletions
-26
View File
@@ -15,14 +15,6 @@ func JSONObject(raw []byte) map[string]any {
return object
}
func NestedString(value any, keys ...string) string {
found := nestedValue(value, keys...)
if found == nil {
return ""
}
return strings.TrimSpace(fmt.Sprint(found))
}
func StringAtPath(value any, path string) string {
found := ValueAtPath(value, path)
if found == nil {
@@ -46,21 +38,3 @@ func ValueAtPath(value any, path string) any {
}
return current
}
func nestedValue(value any, keys ...string) any {
object, ok := value.(map[string]any)
if !ok {
return nil
}
for _, key := range keys {
if found, exists := object[key]; exists && found != nil && fmt.Sprint(found) != "" {
return found
}
}
for _, nestedKey := range []string{"data", "result", "order", "transaction", "response"} {
if found := nestedValue(object[nestedKey], keys...); found != nil {
return found
}
}
return nil
}