Skip to content

Instantly share code, notes, and snippets.

@progrium
Last active Aug 25, 2021
Embed
What would you like to do?
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