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 ¶
- type Client
- func (cl *Client) Call(urlPath string, method string, args interface{}, dst interface{}) error
- func (cl *Client) CallForMap(urlPath string, method string, args interface{}) (map[string]interface{}, error)
- func (cl *Client) DeleteAuthHeader()
- func (cl *Client) DeleteCustomHeader(headerName string)
- func (cl *Client) DisableHeaderNamesNormalizing(fix bool)
- func (cl *Client) SetBaseURL(baseURL string)
- func (cl *Client) SetBasicAuthHeader(login string, password string)
- func (cl *Client) SetClientTimeout(duration time.Duration)
- func (cl *Client) SetCustomAuthHeader(authType string, authData string)
- func (cl *Client) SetCustomHeader(headerName string, headerValue string)
- func (cl *Client) SetUserAgent(userAgent string)
- type ErrorCode
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 ¶
package main import ( "github.com/riftbit/jrpc2client" ) func main() { client := jrpc2client.NewClient() //print empty line because BaseURL not setted println(client.BaseURL) }
Output:
func NewClientWithLogger ¶
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 ¶
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.
package main import ( "fmt" "time" "github.com/riftbit/jrpc2client" ) func main() { 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) }
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.
package main import ( "fmt" "time" "github.com/riftbit/jrpc2client" ) func main() { 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) }
Output:
func (*Client) DeleteAuthHeader ¶
func (cl *Client) DeleteAuthHeader()
DeleteAuthHeader clear basic auth header
func (*Client) DeleteCustomHeader ¶
DeleteCustomHeader delete custom header
func (*Client) DisableHeaderNamesNormalizing ¶ added in v1.1.0
SetFixHeaders setting normalize headers or not
func (*Client) SetBaseURL ¶
SetBaseURL setting basic url for API
func (*Client) SetBasicAuthHeader ¶
SetBasicAuthHeader setting basic auth header
func (*Client) SetClientTimeout ¶
SetClientTimeout this method sets globally for client its timeout
func (*Client) SetCustomAuthHeader ¶
SetCustomAuthHeader setting custom auth header with type of auth and auth data
func (*Client) SetCustomHeader ¶
SetCustomHeader setting custom header
func (*Client) SetUserAgent ¶
SetUserAgent setting custom User Agent header