本文整理汇总了Golang中github.com/bketelsen/skynet/client.Query类的典型用法代码示例。如果您正苦于以下问题:Golang Query类的具体用法?Golang Query怎么用?Golang Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ListServices
func ListServices(q *client.Query) {
results := q.FindServices()
for _, service := range results {
fmt.Println(service)
}
}
示例2: ListInstances
func ListInstances(q *client.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)
}
}
示例3: ListRegions
func ListRegions(q *client.Query) {
results := q.FindRegions()
for _, region := range results {
fmt.Println(region)
}
}
示例4: ListHosts
func ListHosts(q *client.Query) {
results := q.FindHosts()
for _, host := range results {
fmt.Println(host)
}
}
示例5: PrintTopology
func PrintTopology(q *client.Query) {
topology := make(map[string]map[string]map[string]map[string][]*service.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][]*service.Service)
}
if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress] == nil {
topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress] = make(map[string]map[string][]*service.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][]*service.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([]*service.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)
}
}
}
}
}
}
示例6: ListServiceVersions
func ListServiceVersions(q *client.Query) {
if q.Service == "" {
fmt.Println("Service name is required")
return
}
results := q.FindServiceVersions()
for _, version := range results {
fmt.Println(version)
}
}
示例7: doSomething
func doSomething(q *client.Query, do func(*rpc.Client, skynet.Logger)) {
log := skynet.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()
}
}