當前位置: 首頁>>代碼示例>>Golang>>正文


Golang skylib.Query類代碼示例

本文整理匯總了Golang中github.com/bketelsen/skynet/skylib.Query的典型用法代碼示例。如果您正苦於以下問題:Golang Query類的具體用法?Golang Query怎麽用?Golang Query使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Query類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ListRegions

func ListRegions(q *skylib.Query) {
	results := q.FindRegions()

	for _, region := range *results {
		fmt.Println(region)
	}
}
開發者ID:repos-go,項目名稱:skynet,代碼行數:7,代碼來源:sky.go

示例2: ListServices

func ListServices(q *skylib.Query) {
	results := q.FindServices()

	for _, service := range *results {
		fmt.Println(service)
	}
}
開發者ID:repos-go,項目名稱:skynet,代碼行數:7,代碼來源:sky.go

示例3: ListHosts

func ListHosts(q *skylib.Query) {
	results := q.FindHosts()

	for _, host := range *results {
		fmt.Println(host)
	}
}
開發者ID:repos-go,項目名稱:skynet,代碼行數:7,代碼來源:sky.go

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

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

示例6: ListServiceVersions

func ListServiceVersions(q *skylib.Query) {
	if *ServiceNameFlag == "" {
		fmt.Println("Service name is required")
		os.Exit(1)
	}

	results := q.FindServiceVersions()

	for _, version := range *results {
		fmt.Println(version)
	}
}
開發者ID:repos-go,項目名稱:skynet,代碼行數:12,代碼來源:sky.go

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

示例8: 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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。