//UnKonwnJSONUnmarshal json
func UnKonwnJSONUnmarshal(data []byte, key string) (vv interface{}) {
var f interface{}
if err := json.Unmarshal(data, &f); err == nil {
m := f.(map[string]interface{})
for k, v := range m {
if key == k {
switch vv := v.(type) {
case string:
fmt.Println(k, "is string", vv)
return vv
case int:
fmt.Println(k, "is int", vv)
case []interface{}:
fmt.Println(k, "is arry", vv)
return vv
case float64:
fmt.Println(k, "is float64", vv)
return vv
default:
fmt.Println(k, "is of a type I don't know how to handle")
}
} else {
continue
}
}
}
return
}
// MissionPerformance method
func (uptokenTask MissionTaskStr) MissionPerformance() (rejson bool) {
uptokenTask.Name = "missionPerformance"
uptoken := createToken()
s := strings.Split(uptoken, ":")
fmt.Println("policy-base64---", s[2])
policy, err := base64.StdEncoding.DecodeString(s[2])
expire := UnKonwnJSONUnmarshal(policy, "deadline")
switch value := expire.(type) {
case float64:
deadline := int64(value)
now := time.Now().Unix()
if now < deadline {
fmt.Println("==", now)
rejson = true
}
fmt.Println("!=", deadline, now)
}
fmt.Println("policy", expire)
if err != nil {
fmt.Println(uptokenTask.Name, "error---", err)
}
return
}
有疑问加站长微信联系(非本文作者)