jrpc2client: github.com/riftbit/jrpc2client Index | Examples | Files

package jrpc2client

import "github.com/riftbit/jrpc2client"

Package jrpc2client implements client for json-rpc 2.0 protocol and based on another packages:

HTTP Client: github.com/valyala/fasthttp

JSON Parser: github.com/pquerna/ffjson/ffjson

Logger: github.com/sirupsen/logrus

Errors: github.com/riftbit/jrpc2errors

Example can be found only in client_test.go at this moment

You can see your godoc rendered as HTML by running a local godoc server. This is great for previewing your godoc before committing changes. To do that, Make sure your code is in GOPATH and run:

godoc -http ":8080"

Go to http://localhost:8080/pkg and you should see your packages on the list.

If you want the raw HTML, you can run:

godoc -url=/pkg/your_package > your_page.html

Index

Examples

Package Files

client.go doc.go helpers.go structs.go

type Client Uses

type Client struct {
    BaseURL string
    // contains filtered or unexported fields
}

Client basic struct that contains all method to work with JSON-RPC 2.0 protocol

func NewClient Uses

func NewClient() *Client

NewClient returns new configured Client to start work with JSON-RPC 2.0 protocol

Code:

client := jrpc2client.NewClient()
//print empty line because BaseURL not setted
println(client.BaseURL)

func NewClientWithLogger Uses

func NewClientWithLogger(logger *logrus.Logger) *Client

NewClientWithLogger returns new configured Client with custom Logger configureation (based on Sirupsen/logrus) to start work with JSON-RPC 2.0 protocol

func (*Client) Call Uses

func (cl *Client) Call(urlPath string, method string, args interface{}, dst interface{}) error

Call run remote procedure on JSON-RPC 2.0 API with parsing answer to provided structure or interface

This function is named ExampleClient_Call(), this way godoc knows to associate it with the Client type and method Call.

Code:


type TestReply struct {
    LogID     string `json:"log_id"`
    UserAgent string `json:"user_agent"`
}

type TestArgs struct {
    ID string
}

client := jrpc2client.NewClient()
client.SetBaseURL("http://127.0.0.1:8080")
dstP := &TestReply{}
client.SetClientTimeout(10 * time.Millisecond)

// final url will be http://127.0.0.1:8080/api
err := client.Call("/api", "demo.TestClientTimeout", TestArgs{ID: "123"}, dstP)
if err != nil {
    panic(err)
}

fmt.Println(dstP.LogID)

func (*Client) CallForMap Uses

func (cl *Client) CallForMap(urlPath string, method string, args interface{}) (map[string]interface{}, error)

CallForMap run remote procedure on JSON-RPC 2.0 API with returning map[string]interface{}

This function is named ExampleClient_CallForMap(), this way godoc knows to associate it with the Client type and method CallForMap.

Code:

type TestArgs struct {
    ID string
}

client := jrpc2client.NewClient()
client.SetBaseURL("http://127.0.0.1:8080")

client.SetClientTimeout(10 * time.Millisecond)
// final url will be http://127.0.0.1:8080/api
dstM, err := client.CallForMap("/api", "demo.TestClientTimeout", TestArgs{ID: "321"})
if err != nil {
    panic(err)
}

val, ok := dstM["log_id"]
if ok != true {
    panic("key log_id not exists")
}

fmt.Println(val)

func (*Client) DeleteAuthHeader Uses

func (cl *Client) DeleteAuthHeader()

DeleteAuthHeader clear basic auth header

func (*Client) DeleteCustomHeader Uses

func (cl *Client) DeleteCustomHeader(headerName string)

DeleteCustomHeader delete custom header

func (*Client) DisableHeaderNamesNormalizing Uses

func (cl *Client) DisableHeaderNamesNormalizing(fix bool)

DisableHeaderNamesNormalizing setting normalize headers or not

func (*Client) SetBaseURL Uses

func (cl *Client) SetBaseURL(baseURL string)

SetBaseURL setting basic url for API

func (*Client) SetBasicAuthHeader Uses

func (cl *Client) SetBasicAuthHeader(login string, password string)

SetBasicAuthHeader setting basic auth header

func (*Client) SetClientTimeout Uses

func (cl *Client) SetClientTimeout(duration time.Duration)

SetClientTimeout this method sets globally for client its timeout

func (*Client) SetCustomAuthHeader Uses

func (cl *Client) SetCustomAuthHeader(authType string, authData string)

SetCustomAuthHeader setting custom auth header with type of auth and auth data

func (*Client) SetCustomHeader Uses

func (cl *Client) SetCustomHeader(headerName string, headerValue string)

SetCustomHeader setting custom header

func (*Client) SetUserAgent Uses

func (cl *Client) SetUserAgent(userAgent string)

SetUserAgent setting custom User Agent header

type ErrorCode Uses

type ErrorCode int

ErrorCode type for error codes

Package jrpc2client imports 12 packages (graph). Updated 2019-05-04. Refresh now. Tools for package owners.