JSONRPC Client/Server

According to the JSON-RPC 2.0 specification, JSON-RPC is a lightweight remote procedure call (RPC) protocol.

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/jsonrpc

Getting Started

// server
func main() {
  s := jsonrpc.NewServer(8080)

	s.Register("echo", func(params gjson.Result) Result {
		logger.Info("params: %s", params.String())

		return Result{
			"name": params.Get("name").String(),
			"age":  18,
		}
	})

	s.Start()
}

// client
func main() {
  c := jsonrpc.NewClient("http://localhost:8080/")

	r, err := c.Invoke("echo", map[string]string{
		"name": "zero",
	})
	if err != nil {
		t.Fatal(err)
	}

	logger.Info("result: %d", r.Get("age").Int())
}

License

GoZoox is released under the MIT License.

GitHub

View Github