Skip to content

First release

Choose a tag to compare

@bep bep released this 12 Aug 17:18
· 27 commits to main since this release
fa2ac98

I'm happy with the internals, and believe those to be solid and well tested.

I'm mostly happy about the API. Theres some missing type info for the dispatcher (for log messages etc.), but I suspect there is enough generic types in there already, so possibly just a type int, I will know more after using this for real. Let me know what you think!

A strongly typed client may look like this:

client, err := execrpc.StartClient(
		execrpc.ClientOptions[model.ExampleRequest, model.ExampleResponse]{
			ClientRawOptions: execrpc.ClientRawOptions{
				Version: 1,
				Cmd:     "go",
				Args:    []string{"run", "./examples/servers/typed"},
			},
			Codec: codecs.JSONCodec[model.ExampleRequest, model.ExampleResponse]{},
		},
	)

result, _ := client.Execute(model.ExampleRequest{Text: "world"})

fmt.Println(result.Hello)

//...

client.Close()

To get the best performance you should keep the client open as long as its needed – and store it as a shared object; it's safe and encouraged to call Execute from multiple goroutines.

And the server side of the above:

func main() {
	server, _ := execrpc.NewServer(
		execrpc.ServerOptions[model.ExampleRequest, model.ExampleResponse]{
			Codec: codecs.JSONCodec[model.ExampleResponse, model.ExampleRequest]{},
			Call: func(d execrpc.Dispatcher, req model.ExampleRequest) model.ExampleResponse {
				return model.ExampleResponse{
					Hello: "Hello " + req.Text + "!",
				}
			},
		},
	)
	if err := server.Start(); err != nil {
		// ... handle error
	}
	_ = server.Wait()
}

Full Changelog: https://github.com/bep/execrpc/commits/v0.1.0