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


Golang Query.FindInstances方法代码示例

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


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

示例1: ListInstances

func ListInstances(q *skylib.Query) {
	results := q.FindInstances()

	for _, instance := range *results {
		fmt.Println(instance.IPAddress + ":" + strconv.Itoa(instance.Port) + " - " + instance.Name + " (" + instance.Version + ")")
	}
}
开发者ID:repos-go,项目名称:skynet,代码行数:7,代码来源:sky.go

示例2: ListInstances

func ListInstances(q *skylib.Query) {
	var regFlag *bool

	if *RegisteredFlag == "true" {
		b := true
		regFlag = &b
	} else if *RegisteredFlag == "false" {
		b := false
		regFlag = &b
	}

	q.Registered = regFlag

	results := q.FindInstances()

	for _, instance := range results {
		registered := ""

		if instance.Registered {
			registered = " [Registered]"
		}

		fmt.Println(instance.Config.ServiceAddr.IPAddress + ":" + strconv.Itoa(instance.Config.ServiceAddr.Port) + " - " + instance.Config.Name + " " + instance.Config.Version + registered)
	}
}
开发者ID:andrebq,项目名称:skynet,代码行数:25,代码来源:sky.go

示例3: PrintTopology

func PrintTopology(q *skylib.Query) {
	topology := make(map[string]map[string]map[string]map[string][]*skylib.Service)

	results := q.FindInstances()

	// Build topology hash first
	for _, instance := range results {
		if topology[instance.Config.Region] == nil {
			topology[instance.Config.Region] = make(map[string]map[string]map[string][]*skylib.Service)
		}

		if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress] == nil {
			topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress] = make(map[string]map[string][]*skylib.Service)
		}

		if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name] == nil {
			topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name] = make(map[string][]*skylib.Service)
		}

		if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version] == nil {
			topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version] = make([]*skylib.Service, 0)
		}

		topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version] = append(topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version], instance)
	}

	// Now we can print the correct heirarchy
	for regionName, region := range topology {
		fmt.Println("Region: " + regionName)

		for hostName, host := range region {
			fmt.Println("\tHost: " + hostName)

			for serviceName, service := range host {
				fmt.Println("\t\tService: " + serviceName)

				for versionName, version := range service {
					fmt.Println("\t\t\tVersion: " + versionName)

					for _, instance := range version {
						registered := ""

						if instance.Registered {
							registered = " [Registered]"
						}

						fmt.Println("\t\t\t\t" + instance.Config.ServiceAddr.IPAddress + ":" + strconv.Itoa(instance.Config.ServiceAddr.Port) + registered)
					}
				}
			}
		}
	}
}
开发者ID:andrebq,项目名称:skynet,代码行数:53,代码来源:sky.go

示例4: doSomething

func doSomething(q *skylib.Query, do func(*rpc.Client, skylib.Logger)) {

	log := skylib.NewConsoleLogger(os.Stderr)
	for _, instance := range q.FindInstances() {
		conn, err := net.Dial("tcp", instance.Config.AdminAddr.String())
		if err != nil {
			log.Item(err)
			continue
		}
		rpcClient := bsonrpc.NewClient(conn)
		do(rpcClient, log)
		conn.Close()
	}
}
开发者ID:andrebq,项目名称:skynet,代码行数:14,代码来源:admin.go


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