Skip to content
No description, website, or topics provided.
Go
Branch: master
Clone or download
Latest commit 8084415 Oct 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE init Oct 5, 2019
README.md add godoc link Oct 5, 2019
go.mod init Oct 5, 2019
http.go init Oct 5, 2019
http_test.go add unit tests Oct 5, 2019

README.md

jsonrpc

GoDoc

Example Usage

package main

import (
    "log"
    "net/http"
    "net/rpc"

    "github.com/kelseyhightower/jsonrpc"
)

type Args struct {
    A, B int
}

type Arith int

func (t *Arith) Multiply(args *Args, reply *int) error {
    *reply = args.A * args.B
    return nil
}

func main() {
    arith := new(Arith)
    rpc.Register(arith)
    http.Handle("/", jsonrpc.Handler(rpc.DefaultServer))
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Build and start the server, then invoke the Arith.Multiply method with curl:

curl http://127.0.0.1:8080 \
  -d '{"method":"Arith.Multiply","params":[{"A": 10, "B":2}], "id": 0}'
{"id":0,"result":20,"error":null}
You can’t perform that action at this time.