Skip to content

Instantly share code, notes, and snippets.

Created Aug 25, 2021
What would you like to do?
simple qtalk rpc server example
// server.go
package main
import (
type service struct{}
func (svc *service) Upper(s string) string {
return strings.ToUpper(s)
// methods can opt-in to receive the call as last argument.
// also, errors can be returned to be received as remote errors.
func (svc *service) Error(s string, c *rpc.Call) error {
return fmt.Errorf("%s [%s]", s, c.Selector)
func main() {
// create a tcp listener
l, err := net.Listen("tcp", "localhost:9999")
if err != nil {
// setup a server using fn.HandlerFrom to
// handle methods from the service type
srv := &rpc.Server{
Codec: codec.JSONCodec{},
Handler: fn.HandlerFrom(new(service)),
// serve until the listener closes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment