当前位置: 首页>>代码示例>>Golang>>正文


Golang TreeError.IsNull方法代码示例

本文整理汇总了Golang中tree_lib.TreeError.IsNull方法的典型用法代码示例。如果您正苦于以下问题:Golang TreeError.IsNull方法的具体用法?Golang TreeError.IsNull怎么用?Golang TreeError.IsNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree_lib.TreeError的用法示例。


在下文中一共展示了TreeError.IsNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: API_INIT

// Init API node for connection to targets
func API_INIT(targets ...string) bool {
	var err tree_lib.TreeError
	err.From = tree_lib.FROM_API_INIT
	if len(targets) == 0 {
		tree_log.Error(err.From, "For running API client you need to specify target node(s) to connect")
		return false
	}
	for _, n := range targets {
		node_info.ChildsNodeInfo[n], err = tree_db.GetNodeInfo(n)
		if !err.IsNull() {
			tree_log.Error(err.From, fmt.Sprintf("Unable Getting target (%s) node info from Node database, ", n), err.Error())
			return false
		}
	}

	rand.Seed(time.Now().UnixNano())
	node_info.CurrentNodeInfo = node_info.NodeInfo{
		Name:   fmt.Sprintf("%s|%s", API_NAME_PREFIX, tree_lib.RandomString(10)),
		Childs: targets,
		// Getting next prime number based on Unix Timestamp nanoseconds and
		// TODO: Think about making this in a different way
		Value: tree_lib.NextPrimeNumber((1 * rand.Int63n(100)) + int64(100)),
	}

	node_info.CurrentNodeValue = big.NewInt(node_info.CurrentNodeInfo.Value)

	// Setting node values based on child list
	node_info.CalculateChildParentNodeValues()

	// After we have child information lets connect to them
	node_info.ChildsConnectionUpdate()

	return true
}
开发者ID:treescale,项目名称:treescale,代码行数:35,代码来源:api_node.go

示例2: TagPath

func TagPath(from_node, tag_name string) (map[string]*big.Int, tree_lib.TreeError) {
	var (
		err              tree_lib.TreeError
		path             = make(map[string]*big.Int)
		nodes_by_tagname []string
	)
	err.From = tree_lib.FROM_TAG_PATH
	nodes_by_tagname, err = tree_db.GetNodesByTagName(tag_name)
	if !err.IsNull() {
		return nil, err
	}
	for _, n := range nodes_by_tagname {
		if check_node[n] {
			targets = append(targets, n)
			path[n], err = NodePath(from_node, n)
			if !err.IsNull() {
				return nil, err
			}
		} else {
			fmt.Println("there is no server with name ", n)
			fmt.Println("ignoring server ", n)
		}
	}
	return path, err
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:get_path.go

示例3: SendToConn

func SendToConn(data []byte, conn *net.TCPConn, path *big.Int) {
	// making variable for combining send data
	var (
		err           tree_lib.TreeError
		path_len_data = make([]byte, 4)
		msg_len_data  = make([]byte, 4)
		path_data     = path.Bytes()
		path_len      = uint32(len(path_data))
		buf           = bytes.Buffer{}
	)

	err.From = tree_lib.FROM_SEND_TO_CONN

	binary.LittleEndian.PutUint32(path_len_data, path_len)
	binary.LittleEndian.PutUint32(msg_len_data, path_len+uint32(len(data))+uint32(4))

	buf.Write(msg_len_data)
	buf.Write(path_len_data)
	buf.Write(path_data)
	buf.Write(data)

	if conn != nil {
		_, err.Err = conn.Write(buf.Bytes())
		if !err.IsNull() {
			tree_log.Error(err.From, fmt.Sprintf("Error sending data to path [%s]", path.String()), err.Error())
		}
	}

	buf.Reset()
}
开发者ID:treescale,项目名称:treescale,代码行数:30,代码来源:network.go

示例4: GroupPath

func GroupPath(from_node, group_name string) (map[string]*big.Int, tree_lib.TreeError) {
	var (
		path           = make(map[string]*big.Int)
		err            tree_lib.TreeError
		nodes_in_group []string
	)
	err.From = tree_lib.FROM_GROUP_PATH
	nodes_in_group, err = tree_db.GetGroupNodes(group_name)
	if !err.IsNull() {
		return nil, err
	}
	for _, n := range nodes_in_group {
		if check_node[n] {
			targets = append(targets, n)
			path[n], err = NodePath(from_node, n)
			if !err.IsNull() {
				return nil, err
			}
		} else {
			fmt.Println("there is no server with name ", n)
			fmt.Println("ignoring server ", n)
		}
	}
	return path, err
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:get_path.go

示例5: 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())
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:32,代码来源:handle_exec.go

示例6: 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
}
开发者ID:treescale,项目名称:treescale,代码行数:35,代码来源:api.go

示例7: 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

示例8: 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())
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:25,代码来源:handle_event.go

示例9: 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
}
开发者ID:treescale,项目名称:treescale,代码行数:10,代码来源:node.go

示例10: 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)
}
开发者ID:treescale,项目名称:treescale,代码行数:13,代码来源:event.go

示例11: 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

示例12: HandleApiCommand

func HandleApiCommand(cmd_data []byte, api_out io.Writer) {
	var (
		err tree_lib.TreeError
		cmd DockerCmd
	)
	err.From = tree_lib.FROM_HANDLE_API_COMMAND
	err.Err = ffjson.Unmarshal(cmd_data, &cmd)
	if !err.IsNull() {
		writeOutput(api_out, true, fmt.Sprintf("--- Unable to parse Container command data: %s", string(cmd_data)), map[string]string{})
		return
	}

	ContainerCommands(&cmd, api_out)
	fmt.Println(string(cmd_data))
}
开发者ID:treescale,项目名称:treescale,代码行数:15,代码来源:commands.go

示例13: triggerInitEvent

func triggerInitEvent() tree_lib.TreeError {
	var (
		err             tree_lib.TreeError
		dock_containers []docker.APIContainers
	)
	err.From = tree_lib.FROM_TRIGGER_INIT_EVENT
	dock_containers, err.Err = DockerClient.ListContainers(docker.ListContainersOptions{All: false})
	if !err.IsNull() {
		return err
	}

	// Triggering event with currently running Docker containers inside
	tree_event.Trigger(&tree_event.Event{Name: tree_event.ON_DOCKER_INIT, LocalVar: dock_containers})
	return err
}
开发者ID:treescale,项目名称:treescale,代码行数:15,代码来源:docker.go

示例14: 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)
}
开发者ID:treescale,项目名称:treescale,代码行数:16,代码来源:handle_info.go

示例15: 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
	}
}
开发者ID:treescale,项目名称:treescale,代码行数:18,代码来源:config.go


注:本文中的tree_lib.TreeError.IsNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。