mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-07 08:13:39 +00:00
40 lines
672 B
Go
40 lines
672 B
Go
package xdrive
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
func jsonWalk(payload []byte, path string) interface{} {
|
||
|
|
var root interface{}
|
||
|
|
if json.Unmarshal(payload, &root) != nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
node := root
|
||
|
|
for _, key := range strings.Split(path, ".") {
|
||
|
|
obj, ok := node.(map[string]interface{})
|
||
|
|
if !ok {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
node, ok = obj[key]
|
||
|
|
if !ok {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return node
|
||
|
|
}
|
||
|
|
|
||
|
|
func jsonString(payload []byte, path string) string {
|
||
|
|
if s, ok := jsonWalk(payload, path).(string); ok {
|
||
|
|
return s
|
||
|
|
}
|
||
|
|
return ""
|
||
|
|
}
|
||
|
|
|
||
|
|
func jsonNumber(payload []byte, path string) int64 {
|
||
|
|
if f, ok := jsonWalk(payload, path).(float64); ok {
|
||
|
|
return int64(f)
|
||
|
|
}
|
||
|
|
return 0
|
||
|
|
}
|