Skip to content

Instantly share code, notes, and snippets.

@asim
Created July 30, 2016 06:56
Show Gist options
  • Save asim/f421a4ca7f23531e1bf186102516ded5 to your computer and use it in GitHub Desktop.
Save asim/f421a4ca7f23531e1bf186102516ded5 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/micro/go-micro/client"
store "github.com/micro/kv-srv/proto/store"
"golang.org/x/net/context"
)
func main() {
req := client.NewRequest("go.micro.srv.kv", "Store.Put", &store.PutRequest{
Item: &store.Item{
Key: "foo",
Value: []byte(`hello world`),
},
})
rsp := store.PutResponse{}
ctx := context.Background()
err := client.Call(ctx, req, &rsp)
if err != nil {
fmt.Println("store.put", err)
return
}
req = client.NewRequest("go.micro.srv.kv", "Store.Get", &store.GetRequest{
Key: "foo",
})
grsp := store.GetResponse{}
err = client.Call(ctx, req, &grsp)
if err != nil {
fmt.Println("store.get", err)
return
}
fmt.Println(string(grsp.Item.Value))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment