Example #1
0
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)
		}
	}
}
Example #2
0
func main() {
	config, _ := skynet.GetClientConfig()

	var err error

	config.Log = skynet.NewConsoleSemanticLogger("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))
}
Example #3
0
func NewFibonacci() (f *Fibonacci) {
	f = new(Fibonacci)

	f.cconfig, _ = skynet.GetClientConfig()
	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
}
Example #4
0
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)
	}
}