本文整理汇总了Golang中tree_lib.TreeError.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang TreeError.Error方法的具体用法?Golang TreeError.Error怎么用?Golang TreeError.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree_lib.TreeError
的用法示例。
在下文中一共展示了TreeError.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
}
示例2: 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
}
示例3: 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)
}
示例4: 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())
}
}
示例5: HandleNodeCommand
func HandleNodeCommand(cmd *cobra.Command, args []string) {
var (
name string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_NODE_COMMAND
name, err.Err = cmd.Flags().GetString("set-name")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
}
// If we have set-name flag then we just setting current_node in database and exiting
if len(name) > 0 {
tree_db.Set(tree_db.DB_RANDOM, []byte("current_node"), []byte(name))
return
}
daemon := false
daemon, err.Err = cmd.Flags().GetBool("daemon")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
if daemon {
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("%s node > %s 2>&1 &", os.Args[0], tree_log.LogFile))
err.Err = cmd.Run()
if !err.IsNull() {
log.Fatal(err.Err)
}
return
}
name, err.Err = cmd.Flags().GetString("name")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
if len(name) == 0 {
current_node_byte, err := tree_db.Get(tree_db.DB_RANDOM, []byte("current_node"))
if !err.IsNull() {
tree_log.Error(err.From, "Getting current node name from Random database, ", err.Error())
return
}
if len(current_node_byte) == 0 {
fmt.Println("Name is important for the first time run")
return
}
} else {
err = tree_node.SetCurrentNode(name)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
}
tree_node.Start()
}
示例6: SetParent
func SetParent(name string) bool {
var err tree_lib.TreeError
err.From = tree_lib.FROM_SET_PARENT
node_info.ParentNodeInfo, err = tree_db.GetNodeInfo(name)
if !err.IsNull() {
tree_log.Error(err.From, "Getting parent node info from Node database, ", err.Error())
return false
}
return true
}
示例7: TriggerFromData
func TriggerFromData(data []byte) {
var (
e = new(Event)
err tree_lib.TreeError
)
err.From = tree_lib.FROM_TRIGGER_FROM_DATA
err.Err = ffjson.Unmarshal(data, e)
if !err.IsNull() {
tree_log.Error(log_from_event, err.Error())
return
}
Trigger(e)
}
示例8: 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())
}
}
示例9: UpdateNodeChange
func UpdateNodeChange(info node_info.NodeInfo) {
var (
ev = &tree_event.Event{}
err tree_lib.TreeError
)
err.From = tree_lib.FROM_UPDATE_NODE_CHANGE
ev.Data, err.Err = ffjson.Marshal(info)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
path := &tree_graph.Path{From: node_info.CurrentNodeInfo.Name, Nodes: []string{"*"}}
ev.Name = tree_event.ON_UPDATE_NODE_INFO
tree_event.Trigger(ev)
tree_event.Emit(ev, path)
}
示例10: RestoreFromConfigDump
func RestoreFromConfigDump(cmd *cobra.Command, args []string) {
var (
dump_file string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_RESTORE_FROM_CONFIG_DUMP
dump_file, err.Err = cmd.Flags().GetString("file")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
err = tree_db.LoadFromDumpPath(dump_file)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
}
示例11: 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)
}
示例12: PathFiles
func PathFiles(conf_type string, paths []string) ([]string, tree_lib.TreeError) {
var (
err_r tree_lib.TreeError
names []string
FileNames func(path string) (err tree_lib.TreeError)
)
err_r.From = tree_lib.FROM_PATH_FILES
FileNames = func(path string) (err tree_lib.TreeError) {
err.From = tree_lib.FROM_PATH_FILES
files_in_dir, e := ioutil.ReadDir(path)
err.Err = e
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
for _, a := range files_in_dir {
if !a.IsDir() {
if strings.Replace(filepath.Ext(a.Name())[0:], ".", "", 1) == conf_type {
names = append(names, fmt.Sprintf("%s/%s", path, a.Name()))
}
} else {
err = FileNames(fmt.Sprintf("%s/%s", path, a.Name()))
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
}
}
return
}
for _, a := range paths {
if string([]rune(a)[len(a)-1]) == "/" {
a = a[:len(a)-1]
}
err_r = FileNames(a)
if !err_r.IsNull() {
tree_log.Error(err_r.From, err_r.Error())
return nil, err_r
}
}
return names, err_r
}
示例13: HandleInspect
func HandleInspect(cmd *cobra.Command, args []string) {
var (
node string
target []string
tag []string
group []string
container string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_INSPECT
node, err.Err = cmd.Flags().GetString("node")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
target, err.Err = cmd.Flags().GetStringSlice("target")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
tag, err.Err = cmd.Flags().GetStringSlice("tag")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
group, err.Err = cmd.Flags().GetStringSlice("group")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
container, err.Err = cmd.Flags().GetString("container")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
var (
docker_cmd = tree_docker.DockerCmd{}
)
docker_cmd.Content = make(map[string]string)
docker_cmd.Command = tree_docker.COMMAND_DOCKER_CONTAINER_INSPECT
docker_cmd.Content["container"] = container
SendDockerCommand(docker_cmd, node, target, tag, group)
}
示例14: HandleList
func HandleList(cmd *cobra.Command, args []string) {
var (
node string
target []string
tag []string
group []string
err tree_lib.TreeError
)
err.From = tree_lib.FROM_HANDLE_LIST
node, err.Err = cmd.Flags().GetString("node")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
target, err.Err = cmd.Flags().GetStringSlice("target")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
tag, err.Err = cmd.Flags().GetStringSlice("tag")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
group, err.Err = cmd.Flags().GetStringSlice("group")
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
var (
docker_cmd = tree_docker.DockerCmd{}
)
docker_cmd.Content = make(map[string]string)
if cmd.Parent().Name() == "container" {
docker_cmd.Command = tree_docker.COMMAND_DOCKER_CONTAINER_LIST
} else {
docker_cmd.Command = tree_docker.COMMAND_DOCKER_IMAGE_LIST
}
docker_cmd.Content["all"] = "yes"
SendDockerCommand(docker_cmd, node, target, tag, group)
}
示例15: handle_api_or_parent_connection
func handle_api_or_parent_connection(conn *net.TCPConn) {
defer conn.Close() // Connection should be closed, after return this function
var (
err tree_lib.TreeError
msg_data []byte
info_data []byte
conn_name string
is_api = false
conn_node_info node_info.NodeInfo
api_val *big.Int
)
err.From = tree_lib.FROM_HANDLE_API_OR_PARENT_CONNECTION
// Making basic handshake to check the API validation
// Connected Parent receiving name of the child(current node) and checking is it valid or not
// if it is valid name then parent sending his name as an answer
// otherwise it sending CLOSE_CONNECTION_MARK and closing connection
info_data, err.Err = ffjson.Marshal(node_info.CurrentNodeInfo)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
_, err.Err = tree_lib.SendMessage(info_data, conn)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
info_data, err = tree_lib.ReadMessage(conn)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
conn_name = string(info_data)
if conn_name == CLOSE_CONNECTION_MARK {
tree_log.Info(err.From, "Connection closed by parent node. Bad tree network handshake ! ", "Parent Addr: ", conn.RemoteAddr().String())
return
}
err.Err = ffjson.Unmarshal(info_data, &conn_node_info)
if !err.IsNull() {
tree_log.Error(err.From, err.Error())
return
}
if strings.Contains(conn_node_info.Name, tree_api.API_NAME_PREFIX) {
api_val = big.NewInt(conn_node_info.Value)
api_connections[api_val] = conn
is_api = true
} else {
// TODO: Think about conn_node_info if we need to more checking for parent node info
parentConnection = conn
}
if is_api {
tree_event.TriggerWithData(tree_event.ON_API_CONNECTED, info_data)
} else {
tree_event.TriggerWithData(tree_event.ON_PARENT_CONNECTED, info_data)
}
// Listening parent messages
for {
msg_data, err = tree_lib.ReadMessage(conn)
if !err.IsNull() {
tree_log.Error(err.From, " reading data from -> ", conn_name, " ", err.Error())
break
}
// Handling message events
handle_message(is_api, true, msg_data)
}
if is_api {
api_connections[api_val] = nil
delete(api_connections, api_val)
tree_event.TriggerWithData(tree_event.ON_API_DISCONNECTED, info_data)
} else {
parentConnection = nil
tree_event.TriggerWithData(tree_event.ON_PARENT_DISCONNECTED, info_data)
}
}