本文整理汇总了Golang中github.com/pquerna/ffjson/ffjson.Marshal函数的典型用法代码示例。如果您正苦于以下问题:Golang Marshal函数的具体用法?Golang Marshal怎么用?Golang Marshal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Marshal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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())
}
}
示例2: main
func main() {
r := new(RetNode)
r.Name = "sunsc"
r.Sex = "male"
r.Age = 36
buf, err := json.Marshal(r)
log.Println("err==>", err, "| buf=>", string(buf))
secr := new(ReqCardInfoType)
secr.ApiName = "test"
secr.Id = "72789765231"
secr.BizApiCode = "0005000400000001"
buf, err = json.Marshal(secr)
log.Println("err==>", err, "| buf=>", string(buf))
}
示例3: HandleExecCommand
// Executing some commands using exec.Command functionality from Go in OS
func HandleExecCommand(e *tree_event.Event, api_cmd Command) {
var (
out = &WriterCallback{BufferMaxSize: 1024}
cmd_str = string(api_cmd.Data)
cmd_options = strings.Split(cmd_str, " ")
cmd = exec.Command(cmd_options[0], cmd_options[1:]...)
err tree_lib.TreeError
ev_data []byte
)
err.From = tree_lib.FROM_HANDLE_EXEC_COMMAND
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()
cmd.Stdout = out
cmd.Stderr = out
err.Err = cmd.Run()
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
}
示例4: SendCommand
func SendCommand(cmd *Command, path *tree_graph.Path, cb func(*tree_event.Event, Command) bool) (err tree_lib.TreeError) {
// If command ID not set just setting random string
if len(cmd.ID) == 0 {
cmd.ID = tree_lib.RandomString(10)
}
var (
cmd_data []byte
)
cmd_data, err.Err = ffjson.Marshal(cmd)
if !err.IsNull() {
err.From = tree_lib.FROM_SEND_COMMAND
return
}
e := &tree_event.Event{
Name: tree_event.ON_API_COMMAND,
Data: cmd_data,
FromApi: node_info.CurrentNodeInfo.Value,
From: path.From,
}
tree_event.Emit(e, path)
if cb != nil {
subscribed_command_callbacks[cmd.ID] = cb_str{f: cb, c: make(chan bool)}
<-subscribed_command_callbacks[cmd.ID].c
}
return
}
示例5: 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)
}
示例6: FillDatabase
func FillDatabase(listApps []App) {
for _, app := range listApps {
appdb.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte("AppBucket"))
if err != nil {
return fmt.Errorf("create bucket: %s", err)
}
serialize, err := json.Marshal(app)
if err != nil {
return fmt.Errorf("Error Marshaling data: %s", err)
}
err = b.Put([]byte(app.Guid), serialize)
if err != nil {
return fmt.Errorf("Error inserting data: %s", err)
}
return nil
})
}
}
示例7: GetMsgHandler
///从数据库pull消息
func GetMsgHandler(w http.ResponseWriter, req *http.Request) {
//获取客户端通过GET/POST方式传递的参数
var retmsg string
req.ParseForm()
param1, found1 := req.Form["topic"]
param2, _ := req.Form["limit"]
if !found1 {
retmsg = "请勿非法访问"
}
topic := param1[0]
limit, err := strconv.Atoi(param2[0])
if err != nil {
retmsg = "请勿非法访问"
}
if topic != "" {
dblist := models.GetMessagesForField("topic", topic, limit)
msgjson, _ := ffjson.Marshal(dblist)
retmsg = string(msgjson)
} else {
retmsg = "topic is null"
}
io.WriteString(w, retmsg)
}
示例8: main
func main() {
fmt.Println("helloworld")
DbaEnvrEx := buildEnvr()
var listCard = make([]TCARD, 0)
DbaEnvrEx.Select(&listCard, "SELECT * FROM TBL_CARD")
t0 := time.Now()
//result, _ := json.Marshal(listCard)
result, _ := ffjson.Marshal(listCard)
t1 := time.Since(t0)
fmt.Println(t1)
fmt.Println(string(result))
/*
icount, ERR := DbaEnvrEx.SelectInt("SELECT COUNT(*) AS ICOUNT FROM TBL_CARD") //select count(*) as icount from tbl_card
checkErr(ERR, "NULL")
fmt.Println(icount)
*/
/*
var listData = make([]TCARD, 0)
_, eror := DbaEnvrEx.Select(&listData, "SELECT CARD_CODE,CARD_NAME,CARD_ZCTM,CARD_ZCYZ FROM TBL_CARD ORDER BY CARD_CODE")
if eror != nil {
fmt.Println(len(listData))
}
*/
}
示例9: PostMsgHandler
func PostMsgHandler(w http.ResponseWriter, req *http.Request) {
//获取客户端通过GET/POST方式传递的参数
req.ParseForm()
param1, found1 := req.Form["sendmsg"]
result := NewBaseJsonBean()
if !found1 {
result.Code = -99
result.Message = "请勿非法访问"
}
fdata := param1[0]
if fdata != "" {
faction := "POST"
furl := "http://nsq-ttthzygi35.tenxcloud.net:20157/put?topic=test"
result.Code = 100
result.Message = lib.HttpDo_NSQ(faction, furl, fdata)
} else {
result.Code = 101
result.Message = "消息不能为空,请重新发送!"
}
//向客户端返回JSON数据,用到了ffjson包,据说比自带的json效率高3倍
//bytes, _ := json.Marshal(result)
bytes, _ := ffjson.Marshal(result)
io.WriteString(w, string(bytes))
}
示例10: NetworkEmmit
func NetworkEmmit(e *tree_event.Event, path *tree_graph.Path) (err tree_lib.TreeError) {
var (
sdata []byte
p *big.Int
)
err.From = tree_lib.FROM_NETWORK_EMIT
// Calling get value, because maybe some one will calculate this path before calling this functions
// If path is not calculated yet, it will be automatically calculated in GetValue function
p, err = path.GetValue()
if !err.IsNull() {
return
}
// If we emitting from API then we need to multiply path with connected node
// For sending data through him
if strings.Contains(node_info.CurrentNodeInfo.Name, tree_api.API_NAME_PREFIX) {
p.Mul(p, node_info.ChildsNodeValue[path.From])
}
// If from not set, setting it before network sending
if len(e.From) == 0 {
e.From = node_info.CurrentNodeInfo.Name
}
sdata, err.Err = ffjson.Marshal(e)
if !err.IsNull() {
return
}
SendToPath(sdata, p)
return
}
示例11: SetPathValues
func SetPathValues() (err tree_lib.TreeError) {
var (
nodes []node_info.NodeInfo
prime int64
value []byte
)
err.From = tree_lib.FROM_SET_PATH_VALUES
nodes, err = ListNodeInfos()
if !err.IsNull() {
return
}
prime = 2
for _, n := range nodes {
n.Value = prime
value, err.Err = ffjson.Marshal(n)
if !err.IsNull() {
return
}
err = Set(DB_NODE, []byte(n.Name), value)
if !err.IsNull() {
return
}
prime = tree_lib.NextPrimeNumber(prime)
}
return
}
示例12: apiRequest
// Perform a B2 API request with the provided request and response objects
func (c *B2) apiRequest(apiPath string, request interface{}, response interface{}) error {
body, err := ffjson.Marshal(request)
if err != nil {
return err
}
defer ffjson.Pool(body)
if c.Debug {
log.Println("----")
log.Printf("apiRequest: %s %s", apiPath, body)
}
err = c.tryAPIRequest(apiPath, body, response)
// Retry after non-fatal errors
if b2err, ok := err.(*B2Error); ok {
if !b2err.IsFatal() && !c.NoRetry {
if c.Debug {
log.Printf("Retrying request %q due to error: %v", apiPath, err)
}
return c.tryAPIRequest(apiPath, body, response)
}
}
return err
}
示例13: HandleTriggerCustomEvent
func HandleTriggerCustomEvent(e *tree_event.Event, api_cmd Command) {
var (
out = &WriterCallback{BufferMaxSize: 1024}
event_name = string(api_cmd.Data)
err tree_lib.TreeError
ev_data []byte
)
err.From = tree_lib.FROM_TRIGGER_CUSTOM_EVENT
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()
err = custom_event.Trigger(event_name, out)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
}
示例14: toJSON
func toJSON(o interface{}) string {
bytes, err := ffjson.Marshal(o)
if err != nil {
log.Fatal(err)
}
return string(bytes)
}
示例15: SendDockerCommand
func SendDockerCommand(cmd tree_docker.DockerCmd, node string, target []string, tag []string, group []string) {
var err tree_lib.TreeError
if !tree_api.API_INIT(node) {
fmt.Println("Unable to init api client")
fmt.Println("Exiting ...")
return
}
err.From = tree_lib.FROM_SEND_DOCKER_COMMAND
var (
api_cmd = tree_api.Command{}
wait = make(chan bool)
)
api_cmd.ID = tree_lib.RandomString(20)
api_cmd.Data, err.Err = ffjson.Marshal(cmd)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
api_cmd.CommandType = tree_api.COMMAND_CONTAINER
tree_event.ON(tree_event.ON_CHILD_CONNECTED, func(ev *tree_event.Event) {
path := &tree_graph.Path{From: node, Nodes: target, Groups: group, Tags: tag}
tree_api.SendCommand(&api_cmd, path, func(e *tree_event.Event, c tree_api.Command) bool {
fmt.Println(string(c.Data))
fmt.Println(c.Ended)
if c.Ended {
return false
}
return true
})
wait <- true
})
<-wait
}