mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-22 22:58:03 +03:00
https://github.com/XTLS/Xray-core/pull/5645#issuecomment-3849778103 https://github.com/XTLS/Xray-core/pull/5645#issuecomment-3851839033 https://github.com/XTLS/Xray-core/pull/6745#issuecomment-5627294204 https://github.com/XTLS/Xray-core/pull/6748#issuecomment-5660444946 https://github.com/XTLS/Xray-core/pull/6748#issuecomment-5719209642 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
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
|
|
}
|