Categorygithub.com/go-zoox/jsonrpc
modulepackage
1.2.2
Repository: https://github.com/go-zoox/jsonrpc.git
Documentation: pkg.go.dev

# README

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
package main

import (
	"context"

	"github.com/go-zoox/jsonrpc"
	"github.com/go-zoox/jsonrpc/server"
	"github.com/go-zoox/logger"
)

func main() {
	s := server.New()

	s.Register("echo", func(ctx context.Context, params jsonrpc.Params) (jsonrpc.Result, error) {
		logger.Info("params: %s", params)

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

	s.Run()
}
// client
package main

import (
	"context"

	"github.com/go-zoox/core-utils/cast"
	"github.com/go-zoox/jsonrpc"
	"github.com/go-zoox/jsonrpc/client"
	"github.com/go-zoox/logger"
)

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

	r, err := c.Call(context.Background(), "echo", jsonrpc.Params{
		"name": "zero",
	})
	if err != nil {
		logger.Errorf("failed to call: %s", err)
		return
	}

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

License

GoZoox is released under the MIT License.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Constants

JSONRPCDefaultPath is the path of JSON-RPC.
JSONRPCVersion is the version of JSON-RPC.

# Variables

Version is the current version of the jsonrpc package.

# Structs

Error is a JSON-RPC error.
Request is a JSON-RPC request.
Response is a JSON-RPC response.

# Type aliases

Params is a map of params.
Result is a map of result.