README

GoLang jrpc2client (early beta)

Website | Blog

license GoDoc Coverage Status Build Status Go Report Card

This is a json-rpc 2.0 client package for golang based on:

to get high perfomance

This package is still in development

Examples

Without custom logger settings
package main

import (
	"github.com/riftbit/jrpc2client"
)

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

func main() {
	client := jrpc2client.NewClient()

	client.SetBaseURL("http://127.0.0.1:65001")
	client.SetUserAgent("JsonRPC Test Client")
	client.SetBasicAuth("user", "password")

	dstT := &TestReply{}
	err := client.Call("/api", "demo.Test", TestArgs{ID: "TESTER_ID_1"}, dstT)
	if err != nil {
		panic(err)
	}
	println(dstT.LogID)
}
With custom logger settings
package main

import (
	"github.com/riftbit/jrpc2client"
)

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

func main() {
	logger := &logrus.Logger{
    		Out:       os.Stdout,
    		Formatter: &logrus.JSONFormatter{DisableTimestamp: false},
    		Level:     logrus.DebugLevel,
    }

    client := jrpc2client.NewClientWithLogger(logger)

    client.SetBaseURL("http://127.0.0.1:65001")
    client.SetUserAgent("JsonRPC Test Client")
    client.SetBasicAuth("user", "password")

    dstT := &TestReply{}
    err := client.Call("/api", "demo.Test", TestArgs{ID: "TESTER_ID_3"}, dstT)
    if err != nil {
    		panic(err)
    }
    println(dstT.LogID)
}

Benchmark results

Expand ▾ Collapse ▴

Documentation

Overview

    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

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Client

    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

      func NewClient() *Client

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

        Example
        Output:
        
        

        func NewClientWithLogger

        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

          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

            Example

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

              Output:
              
              

              func (*Client) CallForMap

              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{}

                Example

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

                  Output:
                  
                  

                  func (*Client) DeleteAuthHeader

                  func (cl *Client) DeleteAuthHeader()

                    DeleteAuthHeader clear basic auth header

                    func (*Client) DeleteCustomHeader

                    func (cl *Client) DeleteCustomHeader(headerName string)

                      DeleteCustomHeader delete custom header

                      func (*Client) DisableHeaderNamesNormalizing

                      func (cl *Client) DisableHeaderNamesNormalizing(fix bool)

                        SetFixHeaders setting normalize headers or not

                        func (*Client) SetBaseURL

                        func (cl *Client) SetBaseURL(baseURL string)

                          SetBaseURL setting basic url for API

                          func (*Client) SetBasicAuthHeader

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

                            SetBasicAuthHeader setting basic auth header

                            func (*Client) SetClientTimeout

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

                              SetClientTimeout this method sets globally for client its timeout

                              func (*Client) SetCustomAuthHeader

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

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

                                func (*Client) SetCustomHeader

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

                                  SetCustomHeader setting custom header

                                  func (*Client) SetUserAgent

                                  func (cl *Client) SetUserAgent(userAgent string)

                                    SetUserAgent setting custom User Agent header

                                    type ErrorCode

                                    type ErrorCode int

                                      ErrorCode type for error codes