Add GetJsonValue Func
This commit is contained in:
parent
3ac29277e4
commit
70618db06a
32
util.go
32
util.go
@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,3 +50,33 @@ func GetURLValue(Url, key string) string {
|
|||||||
//fmt.Println(query.Get(key))
|
//fmt.Println(query.Get(key))
|
||||||
return query.Get(key)
|
return query.Get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//return result
|
||||||
|
func SetJsonValue(sjson, key, value string) (RJson string) {
|
||||||
|
var m map[string]interface{}
|
||||||
|
m = make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(sjson), &m)
|
||||||
|
CheckErr(err)
|
||||||
|
m[key] = value
|
||||||
|
data, _ := json.Marshal(m)
|
||||||
|
return string(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns a json
|
||||||
|
func MarshalMSData(u MSData) string {
|
||||||
|
type MSDataOnlyString struct {
|
||||||
|
TgId string `json:"tgId"`
|
||||||
|
RefreshToken string `json:"refreshToken"`
|
||||||
|
MsId string `json:"msId"`
|
||||||
|
Uptime string `json:"uptime"`
|
||||||
|
Other string `json:"other"`
|
||||||
|
}
|
||||||
|
var MSNoTime MSDataOnlyString
|
||||||
|
MSNoTime.TgId = strconv.FormatInt(u.tgId, 10)
|
||||||
|
MSNoTime.RefreshToken = u.refreshToken
|
||||||
|
MSNoTime.MsId = u.msId
|
||||||
|
MSNoTime.Uptime = u.uptime.Format("2006-01-02 15:04:05")
|
||||||
|
MSNoTime.Other = u.other
|
||||||
|
result, _ := json.Marshal(MSNoTime)
|
||||||
|
return string(result)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user