本文整理汇总了Golang中github.com/bketelsen/skynet/client.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
config, _ := skynet.GetClientConfig()
var err error
config.Log = skynet.NewConsoleLogger("TestServiceClient", os.Stderr)
client := client.NewClient(config)
// This will not fail if no services currently exist, as connections are created on demand
// this saves from chicken and egg issues with dependencies between services
service := client.GetService("TestService", "", "", "") // any version, any region, any host
// This on the other hand will fail if it can't find a service to connect to
in := map[string]interface{}{
"data": "Upcase me!!",
}
out := map[string]interface{}{}
err = service.Send(nil, "Upcase", in, &out)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(out["data"].(string))
}
开发者ID:yahame,项目名称:skynet,代码行数:27,代码来源:client.go
示例2: main
func main() {
config, _ := skynet.GetClientConfigFromFlags()
client := client.NewClient(config)
service := client.GetService("Sleeper", "", "", "")
service.SetTimeout(1*time.Second, 10*time.Second)
req := sleeper.Request{
Message: "Hello!",
Duration: 5 * time.Second,
}
resp := sleeper.Response{}
start := time.Now()
err := service.Send(nil, "Sleep", req, &resp)
duration := time.Now().Sub(start).Nanoseconds()
fmt.Printf("request took %dns\n", duration)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%s -> %s\n", req.Message, resp.Message)
}
}
开发者ID:sdmajor,项目名称:skynet,代码行数:28,代码来源:sleepclient.go
示例3: main
func main() {
config, args := skynet.GetClientConfig()
client := client.NewClient(config)
service := client.GetService("Fibonacci", "", "", "")
if len(args) == 0 {
fmt.Printf("Usage: %s <positive number>*\n", args[0])
return
}
for _, arg := range args[1:] {
index, err := strconv.Atoi(arg)
if err != nil {
panic(err)
}
req := fibonacci.Request{
Index: index,
}
resp := fibonacci.Response{}
err = service.Send(nil, "Index", req, &resp)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%d -> %d\n", index, resp.Value)
}
}
}
开发者ID:arjloo,项目名称:skynet,代码行数:28,代码来源:fibclient.go
示例4: main
func main() {
config := &skynet.ClientConfig{
DoozerConfig: &skynet.DoozerConfig{},
}
flagset := flag.NewFlagSet("sleepclient", flag.ContinueOnError)
skynet.FlagsForClient(config, flagset)
req := sleeper.Request{
Message: "Hello!",
}
var (
retry time.Duration
giveup time.Duration
)
flagset.DurationVar(&req.Duration, "sleepfor", 5*time.Second, "how long to sleep")
flagset.BoolVar(&req.ExitWhenDone, "exit", false, "have the service call os.Exit(0) when finished sleeping")
flagset.BoolVar(&req.PanicWhenDone, "panic", false, "have the service panic when finished sleeping")
flagset.BoolVar(&req.UnregisterWhenDone, "unregister", false, "have the service unregister when finished sleeping")
flagset.BoolVar(&req.UnregisterHalfwayThrough, "unregister-halfway", false, "have the service unregister half-way through the sleep")
flagset.DurationVar(&retry, "retry", time.Second, "how long to wait before trying again")
flagset.DurationVar(&giveup, "giveup", 5*time.Second, "how long to wait before giving up")
flagset.Parse(os.Args[1:])
config.MaxConnectionsToInstance = 5
client := client.NewClient(config)
service := client.GetService("Sleeper", "", "", "")
service.SetTimeout(retry, giveup)
resp := sleeper.Response{}
start := time.Now()
err := service.Send(nil, "Sleep", req, &resp)
duration := time.Now().Sub(start).Nanoseconds()
fmt.Printf("request took %dns\n", duration)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%s -> %s\n", req.Message, resp.Message)
}
}
开发者ID:yahame,项目名称:skynet,代码行数:52,代码来源:sleepclient.go
示例5: NewFibonacci
func NewFibonacci() (f *Fibonacci) {
f = new(Fibonacci)
f.cconfig, _ = skynet.GetClientConfigFromFlags()
f.client = client.NewClient(f.cconfig)
f.cache = map[int]chan uint64{
0: make(chan uint64, 1),
1: make(chan uint64, 1),
}
f.cache[0] <- 0
f.cache[1] <- 1
return
}
开发者ID:sdmajor,项目名称:skynet,代码行数:15,代码来源:fibservice.go
示例6: getDaemonServiceClient
func getDaemonServiceClient(q *client.Query) (c *client.Client, service *client.ServiceClient) {
config, _ := skynet.GetClientConfigFromFlags(os.Args...)
config.Log = skynet.NewConsoleLogger(os.Stderr)
c = client.NewClient(config)
registered := true
query := &client.Query{
DoozerConn: c.DoozerConn,
Service: "SkynetDaemon",
//Host: "127.0.0.1",
Registered: ®istered,
}
service = c.GetServiceFromQuery(query)
return
}
开发者ID:sdmajor,项目名称:skynet,代码行数:17,代码来源:remote.go
示例7: getDaemonServiceClientForHost
func getDaemonServiceClientForHost(dc *skynet.DoozerConfig, host string) *client.ServiceClient {
config := &skynet.ClientConfig{
DoozerConfig: dc,
}
c := client.NewClient(config)
registered := true
query := &skynet.Query{
DoozerConn: c.DoozerConn,
Service: "SkynetDaemon",
Host: host,
Registered: ®istered,
}
s := c.GetServiceFromQuery(query)
return s
}
开发者ID:arjloo,项目名称:skynet,代码行数:17,代码来源:admin.go
示例8: main
func main() {
config, _ := skynet.GetClientConfig()
client := client.NewClient(config)
service := client.GetService("TutorialService", "1", "Development", "")
req := &TutorialRequest{
Value: 1,
}
resp := &TutorialResponse{}
err := service.Send(nil, "AddOne", req, resp)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(resp.Value)
}
}
开发者ID:arjloo,项目名称:skynet,代码行数:20,代码来源:client.go
示例9: Stop
func Stop(q *skynet.Query) {
cl := client.NewClient(&config)
for _, instance := range filterDaemon(q.FindInstances()) {
cdaemon := daemon.GetDaemonForService(cl, instance)
in := daemon.StopSubServiceRequest{UUID: instance.Config.UUID}
out, err := cdaemon.StopSubService(in)
if err != nil {
if strings.HasPrefix(err.Error(), "No such service UUID") {
// no daemon on the service's machine, shut it down directly
AdminStop(q)
} else {
fmt.Println(err)
}
} else {
stopTemplate.Execute(os.Stdout, out)
}
}
}
开发者ID:arjloo,项目名称:skynet,代码行数:21,代码来源:admin.go
示例10: Deploy
// TODO: this should be smarter about which hosts it deploys to
func Deploy(q *skynet.Query, path string, args ...string) {
cl := client.NewClient(&config)
fmt.Println("deploying " + path + " " + strings.Join(args, ""))
for _, host := range q.FindHosts() {
cdaemon := daemon.GetDaemonForHost(cl, host)
in := daemon.DeployRequest{
ServicePath: path,
Args: shellquote.Join(args...),
}
out, err := cdaemon.Deploy(in)
if err != nil {
fmt.Println(err)
return
}
deployTemplate.Execute(os.Stdout, out)
}
}
开发者ID:arjloo,项目名称:skynet,代码行数:23,代码来源:admin.go
示例11: main
func main() {
config, args := skynet.GetClientConfigFromFlags()
client := client.NewClient(config)
service := client.GetService("Fibonacci", "", "", "")
for _, arg := range args[1:] {
index, err := strconv.Atoi(arg)
if err != nil {
panic(err)
}
req := fibonacci.Request{
Index: index,
}
resp := fibonacci.Response{}
err = service.Send(nil, "Index", req, &resp)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%d -> %d\n", index, resp.Value)
}
}
}
开发者ID:sdmajor,项目名称:skynet,代码行数:23,代码来源:fibclient.go
示例12: Restart
func Restart(q *skynet.Query) {
cl := client.NewClient(&config)
for _, instance := range filterDaemon(q.FindInstances()) {
cdaemon := daemon.GetDaemonForService(cl, instance)
in := daemon.RestartSubServiceRequest{UUID: instance.Config.UUID}
out, err := cdaemon.RestartSubService(in)
if err != nil {
if strings.HasPrefix(err.Error(), "No such service UUID") {
// Commented out for now, we need to determine if we want to try to restart an unmanaged instance, and support it
// no daemon on the service's machine, shut it down directly
//AdminStop(q)
} else {
fmt.Println(err)
}
} else {
restartTemplate.Execute(os.Stdout, out)
}
}
}
开发者ID:arjloo,项目名称:skynet,代码行数:23,代码来源:admin.go
示例13: main
func main() {
flag.Parse()
doozerConfig := &skynet.DoozerConfig{
Uri: *doozer,
AutoDiscover: true,
}
clientConfig := &skynet.ClientConfig{
DoozerConfig: doozerConfig,
ConnectionPoolSize: *requests,
IdleTimeout: (2 * time.Minute),
}
c := make(chan os.Signal, 1)
quitChan := make(chan bool, 1)
requestChan := make(chan string, *requests*3)
workerQuitChan := make(chan bool, 1)
workerWaitGroup := new(sync.WaitGroup)
go watchSignals(c, quitChan)
skynetClient := client.NewClient(clientConfig)
testserviceClient = skynetClient.GetService("TestService", "", "", "")
fibserviceClient = skynetClient.GetService("Fibonacci", "", "", "")
startTime := time.Now().UnixNano()
fmt.Printf("Starting %d Workers\n", *requests)
for i := 0; i < *requests; i++ {
go worker(requestChan, workerWaitGroup, workerQuitChan)
}
requestNum := 0
for {
select {
case <-quitChan:
for i := 0; i < *requests; i++ {
workerQuitChan <- true
}
workerWaitGroup.Wait()
stopTime := time.Now().UnixNano()
successful, _ := strconv.Atoi(successfulRequests.String())
total, _ := strconv.Atoi(totalRequests.String())
failed := total - successful
percentSuccess := int(float64(successful) / float64(total) * 100)
percentFailed := int(float64(failed) / float64(total) * 100)
runtime := (stopTime - startTime) / 1000000
rqps := float64(total) / (float64(runtime) / 1000)
fmt.Println("============================================================================")
fmt.Printf("Completed in %d Milliseconds, %f Requests/s\n", runtime, rqps)
fmt.Printf("\nTotal Requests: %d, Successful: %d (%d%%), Failed: %d (%d%%)\n\n", total, successful, percentSuccess, failed, percentFailed)
return
default:
if requestNum%2 == 0 {
requestChan <- "testservice"
} else {
requestChan <- "fibservice"
}
requestNum++
}
}
}
开发者ID:sdmajor,项目名称:skynet,代码行数:71,代码来源:vagrant.go
注:本文中的github.com/bketelsen/skynet/client.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论