rpc

package
v0.0.0-...-389bc3b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 10 Imported by: 0

README

rpc

Golang rpc client based on http

Documentation

Index

Constants

View Source
const DefaultDailTimeout = time.Duration(5) * time.Second

DefaultDailTimeout 默认超时时间: 5秒

Variables

View Source
var DefaultClient = Client{
	Client: &http.Client{Transport: DefaultTransport},
}

DefaultClient a golang default http client

DefaultTransport 默认 HTTP Transport

View Source
var UserAgent = "Golang rpc package"

UserAgent user agent

Functions

func CallRet

func CallRet(l Logger, ret interface{}, resp *http.Response) (err error)

CallRet parse http response

func NewTransportTimeout

func NewTransportTimeout(dial, resp time.Duration) http.RoundTripper

NewTransportTimeout 返回指定超时时间的 Transport 对象

func NewTransportTimeoutWithConnsPool

func NewTransportTimeoutWithConnsPool(dial, resp time.Duration, poolSize int) http.RoundTripper

NewTransportTimeoutWithConnsPool 返回指定超时时间和最大连接主机数的 Transport 对象

func ResponseError

func ResponseError(resp *http.Response) (err error)

ResponseError return response error

Types

type Client

type Client struct {
	*http.Client
	Header http.Header
}

Client a golang http client

func NewClientTimeout

func NewClientTimeout(dial, resp time.Duration) Client

NewClientTimeout return a golang http client

func (Client) Call

func (r Client) Call(l Logger, ret interface{}, url1 string) (err error)

Call send post method request with url then parse response

func (Client) CallWith

func (r Client) CallWith(l Logger, ret interface{}, url1 string, bodyType string, body io.Reader, bodyLength int) (err error)

CallWith send post method request with url, bodyType, body and bodyLength then parse response

func (Client) CallWith64

func (r Client) CallWith64(l Logger, ret interface{}, url1 string, bodyType string, body io.Reader, bodyLength int64) (err error)

CallWith64 send post method request with url, bodyType, body and bodyLength(64) then parse response

func (Client) CallWithForm

func (r Client) CallWithForm(l Logger, ret interface{}, url1 string, param map[string][]string) (err error)

CallWithForm send post method request with url and form data then parse response

func (Client) CallWithJSON

func (r Client) CallWithJSON(l Logger, ret interface{}, url1 string, param interface{}) (err error)

CallWithJSON send post method request with url and application/json data then parse response

func (Client) Delete

func (r Client) Delete(l Logger, url string) (resp *http.Response, err error)

Delete send delete method request

func (Client) DeleteCall

func (r Client) DeleteCall(l Logger, ret interface{}, url string) (err error)

DeleteCall send delete method request with url

func (Client) Do

func (r Client) Do(l Logger, req *http.Request) (resp *http.Response, err error)

Do 发送 HTTP Request, 并返回 HTTP Response

func (Client) Get

func (r Client) Get(l Logger, url string) (resp *http.Response, err error)

Get send get method request

func (Client) GetCall

func (r Client) GetCall(l Logger, ret interface{}, url1 string) (err error)

GetCall send get method request with url then parse response

func (Client) GetCallWidthHeader

func (r Client) GetCallWidthHeader(l Logger, ret interface{}, url1 string, header http.Header) (err error)

GetCallWidthHeader send get method request with url then parse response

func (Client) GetCallWithForm

func (r Client) GetCallWithForm(l Logger, ret interface{}, url1 string, param map[string][]string) (err error)

GetCallWithForm send get method request with url and param then parse response

func (Client) Head

func (r Client) Head(l Logger, url string) (resp *http.Response, err error)

Head send head method request

func (Client) PostEx

func (r Client) PostEx(l Logger, url string) (resp *http.Response, err error)

PostEx send post method request with url

func (Client) PostWith

func (r Client) PostWith(l Logger, url1 string, bodyType string, body io.Reader, bodyLength int) (resp *http.Response, err error)

PostWith send post method request with url, bodyType, body and bodyLength

func (Client) PostWith64

func (r Client) PostWith64(l Logger, url1 string, bodyType string, body io.Reader, bodyLength int64) (resp *http.Response, err error)

PostWith64 send post method request with url, bodyType, body and bodyLength(64)

func (Client) PostWithForm

func (r Client) PostWithForm(l Logger, url1 string, data map[string][]string) (resp *http.Response, err error)

PostWithForm send post method request with url and form data

func (Client) PostWithJSON

func (r Client) PostWithJSON(l Logger, url1 string, data interface{}) (resp *http.Response, err error)

PostWithJSON send post method request with url and application/json data

func (Client) PutCall

func (r Client) PutCall(l Logger, ret interface{}, url1 string) (err error)

PutCall send put method request with url then parse response

func (Client) PutCallWith

func (r Client) PutCallWith(l Logger, ret interface{}, url1 string, bodyType string, body io.Reader, bodyLength int) (err error)

PutCallWith send put method request with url, bodyType, body and bodyLength then parse response

func (Client) PutCallWith64

func (r Client) PutCallWith64(l Logger, ret interface{}, url1 string, bodyType string, body io.Reader, bodyLength int64) (err error)

PutCallWith64 send post method request with url, bodyType, body and bodyLength(64) then parse response

func (Client) PutCallWithForm

func (r Client) PutCallWithForm(l Logger, ret interface{}, url1 string, param map[string][]string) (err error)

PutCallWithForm send put method request with url and param then parse response

func (Client) PutCallWithJSON

func (r Client) PutCallWithJSON(l Logger, ret interface{}, url1 string, param interface{}) (err error)

PutCallWithJSON send put method request with url and param then parse response

func (Client) PutEx

func (r Client) PutEx(l Logger, url string) (resp *http.Response, err error)

PutEx send put request with url

func (Client) PutWith

func (r Client) PutWith(l Logger, url1 string, bodyType string, body io.Reader, bodyLength int) (resp *http.Response, err error)

PutWith send put method request with url, bodyType, body and bodyLength

func (Client) PutWith64

func (r Client) PutWith64(l Logger, url1 string, bodyType string, body io.Reader, bodyLength int64) (resp *http.Response, err error)

PutWith64 send put method request with url, bodyType, body and bodyLength(64)

func (Client) PutWithForm

func (r Client) PutWithForm(l Logger, url1 string, data map[string][]string) (resp *http.Response, err error)

PutWithForm send put method request with url and form data

func (Client) PutWithJSON

func (r Client) PutWithJSON(l Logger, url1 string, data interface{}) (resp *http.Response, err error)

PutWithJSON send put method request with url and application/json data

type ErrorInfo

type ErrorInfo struct {
	Err     string   `json:"error"`
	Reqid   string   `json:"reqid"`
	Details []string `json:"details"`
	Code    int      `json:"code"`
}

ErrorInfo type

func (*ErrorInfo) Error

func (r *ErrorInfo) Error() string

Error return error message

func (*ErrorInfo) ErrorDetail

func (r *ErrorInfo) ErrorDetail() string

ErrorDetail return error detail

func (*ErrorInfo) HTTPCode

func (r *ErrorInfo) HTTPCode() int

HTTPCode return rpc http StatusCode

type Logger

type Logger interface {
	ReqID() string
	Xput(logs []string)
}

Logger interface

type RespError

type RespError interface {
	ErrorDetail() string
	Error() string
	HttpCode() int
}

RespError interface

Jump to

Keyboard shortcuts

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