Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@progrium
Last active August 25, 2021 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save progrium/3b326e6a02f622ba2fc5370b078890b3 to your computer and use it in GitHub Desktop.
Save progrium/3b326e6a02f622ba2fc5370b078890b3 to your computer and use it in GitHub Desktop.
simple qtalk rpc example client
// client.go
package main
import (
"context"
"log"
"github.com/progrium/qtalk-go/codec"
"github.com/progrium/qtalk-go/fn"
"github.com/progrium/qtalk-go/talk"
)
func main() {
ctx := context.Background()
// use talk.Dial to get a client
client, err := talk.Dial("tcp", "localhost:9999", codec.JSONCodec{})
if err != nil {
log.Fatal(err)
}
defer client.Close()
// call Upper and print the string return value
var ret string
_, err = client.Call(ctx, "Upper", fn.Args{"hello world"}, &ret)
if err != nil {
log.Fatal(err)
}
log.Println(ret)
// call Error and expect err to be the returned error
_, err = client.Call(ctx, "Error", fn.Args{"user error"}, nil)
log.Println(err)
// Output:
// HELLO WORLD
// remote: user error [/Error]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment