本文整理汇总了Golang中github.com/pquerna/ffjson/ffjson.Unmarshal函数的典型用法代码示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Unmarshal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: HandleAddCustomEventHandlers
func HandleAddCustomEventHandlers(e *tree_event.Event, api_cmd Command) {
var (
out = &WriterCallback{BufferMaxSize: 1024}
handler_data map[string]interface{}
err tree_lib.TreeError
ev_data []byte
)
err.From = tree_lib.FROM_ADD_CUSTOM_EVENT
err.Err = ffjson.Unmarshal(api_cmd.Data, &handler_data)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
out.OutCallback = func(data []byte, ended bool) {
cb_cmd := api_cmd
cb_cmd.Ended = ended
cb_cmd.Data = data
ev_data, err.Err = ffjson.Marshal(cb_cmd)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
SendCommandCallback(e, ev_data)
}
defer out.End()
event_name := handler_data["name"].(string)
handles_interfaces := handler_data["handlers"].([]interface{})
var (
handles_interfaces_data []byte
handlers []custom_event.Handler
)
handles_interfaces_data, err.Err = ffjson.Marshal(handles_interfaces)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
err.Err = ffjson.Unmarshal(handles_interfaces_data, &handlers)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
err = custom_event.ON(event_name, handlers...)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
}
开发者ID:treescale,项目名称:treescale,代码行数:50,代码来源:handle_event.go
示例2: parseError
// Looks for an error message in the response body and parses it into a
// B2Error object
func (c *B2) parseError(body []byte) error {
b2err := &B2Error{}
if ffjson.Unmarshal(body, b2err) != nil {
return nil
}
return b2err
}
开发者ID:hack4impact,项目名称:transcribe4all,代码行数:9,代码来源:backblaze.go
示例3: GetUsername
func GetUsername(authorization string) (username, token string, err error) {
var data TokenData
var dataSp []string
var body []byte
token, err = GetAccessToken(authorization)
if err != nil {
return
}
body, err = GetUsernameFromToken(token)
if err != nil {
return
}
err = ffjson.Unmarshal(body, &data)
if err != nil {
return
}
dataSp = strings.Split(data.Aeris, "+")
if len(dataSp) != 2 {
err = errors.New("username errror.")
return
}
username = "+" + dataSp[1]
return
}
开发者ID:ZachBergh,项目名称:common,代码行数:30,代码来源:auth.go
示例4: HandleContainerCommand
func HandleContainerCommand(ev *tree_event.Event, cmd Command) {
var (
out = &WriterCallback{BufferMaxSize: 1024}
docker_cmd = tree_docker.DockerCmd{}
err tree_lib.TreeError
ev_data []byte
)
err.From = tree_lib.FROM_HANDLE_CONTAINER_COMMAND
err.Err = ffjson.Unmarshal(cmd.Data, &docker_cmd)
if !err.IsNull() {
tree_log.Error(err.From, "unable to unmarshal command data as a docker command -> ", err.Error())
return
}
out.OutCallback = func(data []byte, ended bool) {
cb_cmd := cmd
cb_cmd.Ended = ended
cb_cmd.Data = data
ev_data, err.Err = ffjson.Marshal(cb_cmd)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
SendCommandCallback(ev, ev_data)
}
defer out.End()
tree_docker.ContainerCommands(&docker_cmd, out)
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:handle_container.go
示例5: wsSubscribe
func (server *Server) wsSubscribe(conn *websocket.Conn, p *proto.Proto) (userid int64, topics []int32, token string, err error) {
if err = p.ReadWebsocket(conn); err != nil {
return
}
if p.OpCode != define.OP_SUB_REQ {
err = ErrOperation
return
}
sub := new(proto.SubREQ)
err = ffjson.Unmarshal(p.Body, sub)
if err != nil {
return
}
sub.Server = server.Config.Id
if err = server.Subscribe(sub); err != nil {
return
}
userid = sub.UserId
topics = sub.Topics
token = sub.Token
p.Body = nil
p.OpCode = define.OP_SUB_RES
err = p.WriteWebsocket(conn)
return
}
开发者ID:chenjiexin,项目名称:gopush,代码行数:26,代码来源:websocket.go
示例6: Geocode
func (g *Geocoder) Geocode(q, countryCode string, offline bool) (
*jstruct.Location, error) {
res, err := g.geocodeFromCache(q, countryCode)
if err != nil || res != nil || offline {
return res, err
}
r, err := g.rawGeocode(q, countryCode)
if err != nil {
return nil, err
}
defer r.Close()
data, err := ioutil.ReadAll(&io.LimitedReader{
R: r,
N: 4 * 1024 * 1024,
})
if err != nil {
return nil, err
}
res = &jstruct.Location{}
err = ffjson.Unmarshal(data, res)
if err != nil {
return nil, err
}
key, _ := makeKeyAndCountryCode(q, countryCode)
err = g.cache.Put(key, data, buildLocation(res))
if err != nil {
return nil, err
}
return res, err
}
开发者ID:pmezard,项目名称:apec,代码行数:31,代码来源:geocoder.go
示例7: ParseConfigFile
func ParseConfigFile(file string) (conf TreeScaleConf, err tree_lib.TreeError) {
err.From = tree_lib.FROM_PARSE_CONFIG_FILE
switch strings.Replace(filepath.Ext(file), ".", "", 1) {
case "toml":
{
_, err.Err = toml.DecodeFile(file, &conf)
}
case "yaml":
{
var fdata []byte
fdata, err.Err = ioutil.ReadFile(file)
if !err.IsNull() {
return
}
err.Err = yaml.Unmarshal(fdata, &conf)
}
case "json":
{
var fdata []byte
fdata, err.Err = ioutil.ReadFile(file)
if !err.IsNull() {
return
}
err.Err = ffjson.Unmarshal(fdata, &conf)
}
}
return
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:config.go
示例8: Json2map
//json转map
func Json2map(jsonString string) (s map[string]interface{}, err error) {
var result map[string]interface{}
if err := ffjson.Unmarshal([]byte(jsonString), &result); err != nil {
return nil, err
}
return result, nil
}
开发者ID:slygo,项目名称:360baosdk,代码行数:8,代码来源:simpleOutput.go
示例9: GetParentInfo
func GetParentInfo(node string) (node_info.NodeInfo, tree_lib.TreeError) {
var (
err tree_lib.TreeError
pname string
)
err.From = tree_lib.FROM_GET_PARENT_INFO
err = ForEach(DB_NODE, func(key []byte, val []byte) error {
n := node_info.NodeInfo{}
err := ffjson.Unmarshal(val, &n)
if err != nil {
return err
}
if _, ok := tree_lib.ArrayContains(n.Childs, node); ok {
pname = n.Name
return errors.New("Just Err for break")
}
return nil
})
if len(pname) == 0 {
return node_info.NodeInfo{}, tree_lib.TreeError{}
}
// Node relations first element should be parent node
return GetNodeInfo(pname)
}
开发者ID:treescale,项目名称:treescale,代码行数:29,代码来源:node_db.go
示例10: PushAll
// broadcast : push message to all users
func (h *HttpServer) PushAll(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
return
}
var (
bodyBytes []byte
err error
)
defer r.Body.Close()
if bodyBytes, err = ioutil.ReadAll(r.Body); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
msg := &proto.PushMsg{}
err = ffjson.Unmarshal(bodyBytes, msg)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := DefaultMQ.Broadcast(msg); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
return
}
开发者ID:chenjiexin,项目名称:gopush,代码行数:29,代码来源:http.go
示例11: PushTopic
// push message of topic to users who subscribe the topic
func (h *HttpServer) PushTopic(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
return
}
var (
bodyBytes []byte
err error
)
defer r.Body.Close()
if bodyBytes, err = ioutil.ReadAll(r.Body); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
reqmsg := &PushTopicREQ{}
err = ffjson.Unmarshal(bodyBytes, reqmsg)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
servers := DefaultServer.GetTopicServers(reqmsg.Topic)
if len(servers) == 0 {
http.Error(w, "no servers sub the topic", http.StatusInternalServerError)
return
}
if err = DefaultMQ.BroadcastTopic(servers, reqmsg.Topic, reqmsg.Msg); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
return
}
开发者ID:chenjiexin,项目名称:gopush,代码行数:36,代码来源:http.go
示例12: Request
// Request function for send requests to betfair via REST JSON
func (b *Betting) Request(reqStruct interface{}, url BetURL, method string, filter *Filter) error {
req, resp := fasthttp.AcquireRequest(), fasthttp.AcquireResponse()
urlBuild := bytes.NewBuffer([]byte{})
urlBuild.WriteString(string(url))
urlBuild.WriteString("/")
urlBuild.WriteString(method)
urlBuild.WriteString("/")
req.SetRequestURI(urlBuild.String())
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Application", b.ApiKey)
req.Header.Set("X-Authentication", b.SessionKey)
req.Header.SetMethod("POST")
if filter != nil {
filterBody, err := ffjson.Marshal(&filter)
if err != nil {
return err
}
req.SetBody(filterBody)
}
err := fasthttp.Do(req, resp)
if err != nil {
return err
}
if resp.StatusCode() == 400 {
err = ffjson.Unmarshal(resp.Body(), &bettingError)
if err != nil {
return err
}
return fmt.Errorf("Error with code - %s and string - %s", bettingError.Faultcode, bettingError.Faultstring)
}
err = ffjson.Unmarshal(resp.Body(), reqStruct)
if err != nil {
return err
}
return nil
}
开发者ID:Nyarum,项目名称:betting,代码行数:47,代码来源:betting.go
示例13: BenchmarkFFJsonSmall
func BenchmarkFFJsonSmall(b *testing.B) {
for i := 0; i < b.N; i++ {
var data SmallPayload
ffjson.Unmarshal(smallFixture, &data)
nothing(data.Uuid, data.Tz, data.Ua, data.St)
}
}
开发者ID:qband,项目名称:down,代码行数:8,代码来源:benchmark_small_payload_test.go
示例14: enumerateStoredOffers
func enumerateStoredOffers(store *Store,
callback func(offer *jstruct.JsonOffer, do *DeletedOffer) error) error {
// Enumerate deleted offers
ids, err := store.ListDeletedIds()
if err != nil {
return err
}
for _, id := range ids {
deletedIds, err := store.ListDeletedOffers(id)
if err != nil {
return err
}
for _, deleted := range deletedIds {
data, err := store.GetDeleted(deleted.Id)
if err != nil {
return err
}
js := &jstruct.JsonOffer{}
err = ffjson.Unmarshal(data, js)
if err != nil {
return err
}
err = callback(js, &deleted)
if err != nil {
return err
}
}
}
// Enumerate valid offers
ids, err = store.List()
if err != nil {
return err
}
for _, id := range ids {
offer, err := getStoreJsonOffer(store, id)
if err != nil {
return err
}
if offer == nil {
fmt.Printf("skipping %s\n", id)
data, err := store.Get(id)
if err != nil {
fmt.Printf("error %s: %s\n", id, err)
} else if len(data) == 0 {
fmt.Printf("error %s: nil\n", id)
} else {
fmt.Printf("error %s: %s\n", id, string(data))
}
continue
}
err = callback(offer, nil)
if err != nil {
return err
}
}
return nil
}
开发者ID:pmezard,项目名称:apec,代码行数:58,代码来源:duplicates.go
示例15: PushMQ
// push
// does invalidate msg, if it is invalid, ignore it
func (c *CometRpc) PushMQ(msg []byte) (err error) {
m := &proto.MQMsg{}
if err = ffjson.Unmarshal(msg, m); err != nil {
log.Errorf("json.Unmarshal(%s) error(%s)", msg, err)
return
}
c.push(m)
return
}
开发者ID:chenjiexin,项目名称:gopush,代码行数:11,代码来源:comet.go
示例16: TimeFromLine
func (b *esBackend) TimeFromLine(line *[]byte) string {
var f nf
err := ffjson.Unmarshal(*line, &f)
if err != nil {
return time.Now().UTC().Format(b.ctx.cfg.Backend["es"].Index)
}
t, _ := time.Parse(time.RFC3339Nano, f.Ltimestamp)
return t.Format(b.ctx.cfg.Backend["es"].Index)
}
开发者ID:42wim,项目名称:ulog2queue,代码行数:9,代码来源:es.go
示例17: HandleUpdateCommand
func HandleUpdateCommand(ev *tree_event.Event, cmd Command) {
var (
data Command
info node_info.NodeInfo
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_UPDATE_COMMAND
err.Err = ffjson.Unmarshal(ev.Data, &data)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
err.Err = ffjson.Unmarshal(data.Data, &info)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
UpdateNodeChange(info)
SendCommandCallback(ev, ev.Data)
}
开发者ID:treescale,项目名称:treescale,代码行数:18,代码来源:handle_info.go
示例18: HandlPostReciveFirst
func HandlPostReciveFirst(c *gin.Context) (bodyStr, code string) {
body, err := ioutil.ReadAll(c.Request.Body)
CheckError(err)
templCode := TemplCode{}
ffjson.Unmarshal(body, &templCode)
// c.String(200, string(body))
// fmt.Println("打印值", string(body))
bodyStr = string(body)
code = templCode.Code
return
}
开发者ID:slygo,项目名称:360baosdk,代码行数:11,代码来源:common.go
示例19: parseLine
func parseLine(line *[]byte) {
var f nf
var t time.Time
var realRegionName, regionName string
var record *geoip2.City
err := ffjson.Unmarshal(*line, &f)
if err != nil {
*line = []byte("")
log.Error(err, "couldn't unmarshal ", *line)
return
}
if f.Srcip == nil {
log.Error("Packet without source ip, shouldn't happen: ", string(*line))
return
}
// use LRU cache
if val, ok := geoipCache.Get(*f.Srcip); ok {
record = val.(*geoip2.City)
} else {
ip := net.ParseIP(*f.Srcip)
record, _ = geoipDB.City(ip)
geoipCache.Add(*f.Srcip, record)
}
// add @timestamp with zulu (ISO8601 time)
t, _ = time.ParseInLocation(nfLayout, *f.Timestamp, myLocation)
f.Ltimestamp = t.UTC().Format(time.RFC3339Nano)
if record.Location.Longitude != 0 && record.Location.Latitude != 0 {
mylen := len(record.Subdivisions)
if mylen > 0 {
mylen--
realRegionName = record.Subdivisions[mylen].Names["en"]
regionName = record.Subdivisions[mylen].IsoCode
}
f.GeoIP.Longitude = &record.Location.Longitude
f.GeoIP.Latitude = &record.Location.Latitude
f.GeoIP.CountryName = record.Country.Names["en"]
f.GeoIP.Timezone = &record.Location.TimeZone
f.GeoIP.ContinentCode = &record.Continent.Code
f.GeoIP.CityName = record.City.Names["en"]
f.GeoIP.CountryCode2 = &record.Country.IsoCode
f.GeoIP.RealRegionName = &realRegionName
f.GeoIP.RegionName = ®ionName
f.GeoIP.IP = f.Srcip
f.GeoIP.Location = &esGeoIPLocation{f.GeoIP.Longitude, f.GeoIP.Latitude}
f.GeoIP.Coordinates = f.GeoIP.Location
}
*line, _ = ffjson.Marshal(f)
}
开发者ID:42wim,项目名称:ulog2queue,代码行数:54,代码来源:ulog2file.go
示例20: Status
func Status(url string) (resp StatusResp, err error) {
body, err := send(url+"v1/", "")
if err != nil {
return
}
buf := []byte(body)
err = ffjson.Unmarshal(buf, &resp)
return
}
开发者ID:gunsluo,项目名称:dkron-api-go,代码行数:11,代码来源:job_schedule.go
注:本文中的github.com/pquerna/ffjson/ffjson.Unmarshal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论