jsonrpc

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

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}

Documentation

Overview

Package jsonrpc implements a HTTP handler for the net/rpc package using the jsonrpc codec.

This package is largely a workaround to avoid using the HTTP CONNECT method required by the HTTP handlers provided by the net/rpc package, which are not supported by some HTTP proxies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(server *rpc.Server) http.Handler

Handler returns a request handler that serves rpc request by decoding the request and invoking the registered method using the given rpc server.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL