Last active
August 25, 2021 15:58
-
-
Save progrium/3b326e6a02f622ba2fc5370b078890b3 to your computer and use it in GitHub Desktop.
simple qtalk rpc example client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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