Documentation ¶
Index ¶
- Constants
- func AddFilter(filters ...Filter) func(client *defaultRestClient)
- func AddIFilter(filters ...IFilter) func(client *defaultRestClient)
- func ContentLengthFilter(request *http.Request, fc FilterChain) (*http.Response, error)
- func DefaultRequestCreator(method, url string, r io.Reader, params map[string]interface{}) *http.Request
- func NewWrapper(c RestClient, wrapper Wrapper) *clientWrapper
- func NewWrapperContext(c RestClient, wrapper WrapperContext) *clientWrapper
- func RandomId(length int) string
- func SetAutoAccept(v AcceptFlag) func(client *defaultRestClient)
- func SetBufferPool(pool buffer.Pool) func(client *defaultRestClient)
- func SetClientCreator(creator HttpClientCreator) func(client *defaultRestClient)
- func SetConverters(convs []Converter) func(client *defaultRestClient)
- func SetRequestCreator(f RequestCreator) func(client *defaultRestClient)
- func SetRoundTripper(tripper http.RoundTripper) func(client *defaultRestClient)
- func SetTimeout(timeout time.Duration) func(client *defaultRestClient)
- type AcceptFlag
- type AccessTokenAuth
- type BaseConverter
- type BasicAuth
- type Builder
- type ByteConverter
- type ByteDecoder
- type ByteEncoder
- type Converter
- type Decoder
- type DigestAuth
- type DigestReader
- type Encoder
- type Exchange
- type ExchangeContext
- type Filter
- type FilterChain
- type FilterManager
- type HttpClientCreator
- type IFilter
- type JsonConverter
- type JsonDecoder
- type JsonEncoder
- type Log
- type LogFunc
- type MediaType
- type Opt
- type RecoveryFilter
- type RequestCreator
- type RequestEntity
- type ResponseEntity
- type RestClient
- func New(opts ...Opt) RestClient
- func NewAccessTokenAuthClient(client RestClient, auth *AccessTokenAuth) RestClient
- func NewBasicAuthClient(client RestClient, auth *BasicAuth) RestClient
- func NewDigestAuthClient(client RestClient, auth *DigestAuth) RestClient
- func NewLogClient(client RestClient, log *Log) RestClient
- type StringConverter
- type StringDecoder
- type StringEncoder
- type WWWAuthenticate
- type WrapReader
- type Wrapper
- type WrapperContext
- type XmlConverter
- type XmlDecoder
- type XmlEncoder
- type YamlConverter
- type YamlDecoder
- type YamlEncoder
Constants ¶
View Source
const ( MediaTypeAll = "*/*" MediaTypeAtom = "application/atom" MediaTypeAtomXml = "application/atom+xml" MediaTypeFormUrlencoded = "application/x-www-form-urlencoded" MediaTypeJson = "application/json" MediaTypeJsonUtf8 = "application/json;charset=UTF-8" MediaTypeYaml = "application/yaml" MediaTypeYamlUtf8 = "application/yaml;charset=UTF-8" MediaTypeOctetStream = "application/octet-stream" MediaTypePdf = "application/pdf" MediaTypeProblemJson = "application/problem+json" MediaTypeProblemJsonUtf8 = "application/problem+json;charset=UTF-8" MediaTypeXml = "application/xml" MediaTypeProblemXml = "application/problem+xml" MediaTypeRssXml = "application/rss+xml" MediaTypeStreamJson = "application/stream+json" MediaTypeXhtmlXml = "application/xhtml+xml" MediaTypeImageAll = "image/*" MediaTypeImageGif = "image/gif" MediaTypeImageJpeg = "image/jpeg" MediaTypeImagePng = "image/png" MediaTypeMultipartFormData = "multipart/form-data" MediaTypeTextEventStream = "text/event-stream" MediaTypeTextHtml = "text/html" MediaTypeTextMarkdown = "text/markdown" MediaTypeTextPlain = "text/plain" MediaTypeTextXml = "text/xml" )
Variables ¶
This section is empty.
Functions ¶
func AddFilter ¶ added in v0.3.1
func AddFilter(filters ...Filter) func(client *defaultRestClient)
增加处理filter
func AddIFilter ¶ added in v0.3.3
func AddIFilter(filters ...IFilter) func(client *defaultRestClient)
增加处理filter
func ContentLengthFilter ¶ added in v0.3.4
func DefaultRequestCreator ¶ added in v0.0.4
func NewWrapper ¶ added in v0.0.4
func NewWrapper(c RestClient, wrapper Wrapper) *clientWrapper
func NewWrapperContext ¶ added in v0.4.1
func NewWrapperContext(c RestClient, wrapper WrapperContext) *clientWrapper
func SetAutoAccept ¶ added in v0.2.3
func SetAutoAccept(v AcceptFlag) func(client *defaultRestClient)
配置是否自动添加accept
func SetBufferPool ¶ added in v0.3.3
配置内存池
func SetClientCreator ¶ added in v0.4.3
func SetClientCreator(creator HttpClientCreator) func(client *defaultRestClient)
// 配置http客户端创建器
func SetConverters ¶ added in v0.0.5
func SetConverters(convs []Converter) func(client *defaultRestClient)
配置初始转换器列表
func SetRequestCreator ¶ added in v0.0.4
func SetRequestCreator(f RequestCreator) func(client *defaultRestClient)
配置request创建器
func SetRoundTripper ¶ added in v0.0.4
func SetRoundTripper(tripper http.RoundTripper) func(client *defaultRestClient)
配置连接池
func SetTimeout ¶ added in v0.0.3
设置读写超时
Types ¶
type AcceptFlag ¶ added in v0.2.3
type AcceptFlag int
const ( DefaultTimeout = 0 AcceptUserOnly AcceptFlag = 1 AcceptAutoFirst AcceptFlag = 1 << 1 AcceptAutoAll AcceptFlag = 1 << 2 )
type AccessTokenAuth ¶ added in v0.0.11
type AccessTokenAuth struct {
// contains filtered or unexported fields
}
func NewAccessTokenAuth ¶ added in v0.0.11
func NewAccessTokenAuth(accessToken string, tokenBuilder ...func(token string) (string, string)) *AccessTokenAuth
func (*AccessTokenAuth) Exchange ¶ added in v0.0.11
func (b *AccessTokenAuth) Exchange(ex Exchange) Exchange
func (*AccessTokenAuth) Filter ¶ added in v0.3.3
func (auth *AccessTokenAuth) Filter(request *http.Request, fc FilterChain) (*http.Response, error)
func (*AccessTokenAuth) ResetCredentials ¶ added in v0.2.4
func (auth *AccessTokenAuth) ResetCredentials(token string)
type BaseConverter ¶ added in v0.0.5
type BaseConverter struct {
SupportType []MediaType
}
func (*BaseConverter) CanHandler ¶ added in v0.0.5
func (c *BaseConverter) CanHandler(mediaType MediaType) bool
func (*BaseConverter) SupportMediaType ¶ added in v0.0.5
func (c *BaseConverter) SupportMediaType() []MediaType
type BasicAuth ¶ added in v0.0.7
type BasicAuth struct {
// contains filtered or unexported fields
}
func NewBasicAuth ¶ added in v0.0.8
func (*BasicAuth) ResetCredentials ¶ added in v0.2.4
type Builder ¶ added in v0.0.9
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) Build ¶ added in v0.0.9
func (b *Builder) Build() RestClient
type ByteConverter ¶ added in v0.0.5
type ByteConverter struct {
BaseConverter
}
func NewByteConverter ¶ added in v0.0.5
func NewByteConverter() *ByteConverter
func (*ByteConverter) CanDecode ¶ added in v0.2.1
func (c *ByteConverter) CanDecode(o interface{}, mediaType MediaType) bool
func (*ByteConverter) CanEncode ¶ added in v0.2.1
func (c *ByteConverter) CanEncode(o interface{}, mediaType MediaType) bool
func (*ByteConverter) CreateDecoder ¶ added in v0.2.1
func (c *ByteConverter) CreateDecoder(r io.Reader) Decoder
func (*ByteConverter) CreateEncoder ¶ added in v0.2.1
func (c *ByteConverter) CreateEncoder(w io.Writer) Encoder
type ByteDecoder ¶ added in v0.2.1
type ByteDecoder struct {
// contains filtered or unexported fields
}
func (*ByteDecoder) Decode ¶ added in v0.2.1
func (c *ByteDecoder) Decode(result interface{}) (int64, error)
type ByteEncoder ¶ added in v0.2.1
type ByteEncoder struct {
// contains filtered or unexported fields
}
func (*ByteEncoder) Encode ¶ added in v0.2.1
func (c *ByteEncoder) Encode(i interface{}) (int64, error)
type DigestAuth ¶ added in v0.0.8
type DigestAuth struct {
// contains filtered or unexported fields
}
func NewDigestAuth ¶ added in v0.0.8
func NewDigestAuth(username, password string) *DigestAuth
func (*DigestAuth) Exchange ¶ added in v0.0.8
func (b *DigestAuth) Exchange(ex Exchange) Exchange
func (*DigestAuth) Filter ¶ added in v0.3.3
func (auth *DigestAuth) Filter(request *http.Request, fc FilterChain) (*http.Response, error)
func (*DigestAuth) ResetCredentials ¶ added in v0.2.4
func (da *DigestAuth) ResetCredentials(username, password string)
type DigestReader ¶ added in v0.0.8
type DigestReader struct {
// contains filtered or unexported fields
}
func (*DigestReader) Reader ¶ added in v0.0.8
func (dr *DigestReader) Reader(r io.ReadCloser) io.ReadCloser
type ExchangeContext ¶ added in v0.4.1
type FilterChain ¶ added in v0.3.1
type FilterChain []Filter
type FilterManager ¶ added in v0.3.1
type FilterManager FilterChain
func (*FilterManager) Add ¶ added in v0.3.1
func (fc *FilterManager) Add(filter ...Filter)
type HttpClientCreator ¶ added in v0.4.3
type JsonConverter ¶
type JsonConverter struct {
BaseConverter
}
func NewJsonConverter ¶ added in v0.0.5
func NewJsonConverter(supportTypes ...string) *JsonConverter
func (*JsonConverter) CanDecode ¶ added in v0.2.1
func (c *JsonConverter) CanDecode(o interface{}, mediaType MediaType) bool
func (*JsonConverter) CanEncode ¶ added in v0.2.1
func (c *JsonConverter) CanEncode(o interface{}, mediaType MediaType) bool
func (*JsonConverter) CreateDecoder ¶ added in v0.2.1
func (c *JsonConverter) CreateDecoder(r io.Reader) Decoder
func (*JsonConverter) CreateEncoder ¶ added in v0.2.1
func (c *JsonConverter) CreateEncoder(w io.Writer) Encoder
type JsonDecoder ¶ added in v0.2.1
type JsonDecoder struct {
// contains filtered or unexported fields
}
func (*JsonDecoder) Decode ¶ added in v0.2.1
func (c *JsonDecoder) Decode(result interface{}) (int64, error)
type JsonEncoder ¶ added in v0.2.1
type JsonEncoder struct {
// contains filtered or unexported fields
}
func (*JsonEncoder) Encode ¶ added in v0.2.1
func (c *JsonEncoder) Encode(i interface{}) (int64, error)
type MediaType ¶ added in v0.0.5
type MediaType struct {
// contains filtered or unexported fields
}
func BuildMediaType ¶ added in v0.0.5
func ParseMediaType ¶ added in v0.0.5
func (*MediaType) IsWildcard ¶ added in v0.0.10
func (*MediaType) IsWildcardSub ¶ added in v0.0.10
type RecoveryFilter ¶ added in v0.3.3
func NewRecovery ¶ added in v0.3.3
func NewRecovery(log xlog.Logger) *RecoveryFilter
func (*RecoveryFilter) Filter ¶ added in v0.3.3
func (rf *RecoveryFilter) Filter(request *http.Request, fc FilterChain) (resp *http.Response, err error)
type RequestCreator ¶ added in v0.0.4
type RequestEntity ¶ added in v0.3.3
type RequestEntity struct { Body interface{} Reader WrapReader }
func NewRequestEntity ¶ added in v0.3.3
func NewRequestEntity(body interface{}, r WrapReader) *RequestEntity
type ResponseEntity ¶ added in v0.0.8
func NewResponseEntity ¶ added in v0.0.8
func NewResponseEntity(result interface{}) *ResponseEntity
type RestClient ¶
type RestClient interface { AddConverter(conv Converter) GetConverters() []Converter Get(result interface{}, url string, params map[string]interface{}) (int, error) GetContext(ctx context.Context, result interface{}, url string, params map[string]interface{}) (int, error) Post(result interface{}, url string, params map[string]interface{}, requestBody interface{}) (int, error) PostContext(ctx context.Context, result interface{}, url string, params map[string]interface{}, requestBody interface{}) (int, error) Put(result interface{}, url string, params map[string]interface{}, requestBody interface{}) (int, error) PutContext(ctx context.Context, result interface{}, url string, params map[string]interface{}, requestBody interface{}) (int, error) Delete(result interface{}, url string, params map[string]interface{}) (int, error) DeleteContext(ctx context.Context, result interface{}, url string, params map[string]interface{}) (int, error) Head(result interface{}, url string, params map[string]interface{}) (int, error) HeadContext(ctx context.Context, result interface{}, url string, params map[string]interface{}) (int, error) Options(result interface{}, url string, params map[string]interface{}) (int, error) OptionsContext(ctx context.Context, result interface{}, url string, params map[string]interface{}) (int, error) Patch(result interface{}, url string, params map[string]interface{}, requestBody interface{}) (int, error) PatchContext(ctx context.Context, result interface{}, url string, params map[string]interface{}, requestBody interface{}) (int, error) Exchange(result interface{}, url string, method string, params map[string]interface{}, requestBody interface{}) (int, error) ExchangeContext(ctx context.Context, result interface{}, url string, method string, params map[string]interface{}, requestBody interface{}) (int, error) }
func New ¶
func New(opts ...Opt) RestClient
func NewAccessTokenAuthClient ¶ added in v0.0.11
func NewAccessTokenAuthClient(client RestClient, auth *AccessTokenAuth) RestClient
func NewBasicAuthClient ¶ added in v0.0.7
func NewBasicAuthClient(client RestClient, auth *BasicAuth) RestClient
func NewDigestAuthClient ¶ added in v0.0.8
func NewDigestAuthClient(client RestClient, auth *DigestAuth) RestClient
func NewLogClient ¶ added in v0.0.9
func NewLogClient(client RestClient, log *Log) RestClient
type StringConverter ¶ added in v0.0.5
type StringConverter struct {
BaseConverter
}
func NewStringConverter ¶ added in v0.0.5
func NewStringConverter() *StringConverter
func (*StringConverter) CanDecode ¶ added in v0.2.1
func (c *StringConverter) CanDecode(o interface{}, mediaType MediaType) bool
func (*StringConverter) CanEncode ¶ added in v0.2.1
func (c *StringConverter) CanEncode(o interface{}, mediaType MediaType) bool
func (*StringConverter) CreateDecoder ¶ added in v0.2.1
func (c *StringConverter) CreateDecoder(r io.Reader) Decoder
func (*StringConverter) CreateEncoder ¶ added in v0.2.1
func (c *StringConverter) CreateEncoder(w io.Writer) Encoder
type StringDecoder ¶ added in v0.2.1
type StringDecoder struct {
// contains filtered or unexported fields
}
func (*StringDecoder) Decode ¶ added in v0.2.1
func (c *StringDecoder) Decode(result interface{}) (int64, error)
type StringEncoder ¶ added in v0.2.1
type StringEncoder struct {
// contains filtered or unexported fields
}
func (*StringEncoder) Encode ¶ added in v0.2.1
func (c *StringEncoder) Encode(i interface{}) (int64, error)
type WWWAuthenticate ¶ added in v0.0.8
type WWWAuthenticate struct { Algorithm string Realm string Qop []string Nonce string Opaque string }
func ParseWWWAuthenticate ¶ added in v0.0.8
func ParseWWWAuthenticate(s string) *WWWAuthenticate
type WrapReader ¶ added in v0.0.8
type WrapReader func(r io.ReadCloser) io.ReadCloser
type WrapperContext ¶ added in v0.4.1
type WrapperContext func(ex ExchangeContext) ExchangeContext
type XmlConverter ¶ added in v0.0.5
type XmlConverter struct {
BaseConverter
}
func NewXmlConverter ¶ added in v0.0.5
func NewXmlConverter(supportTypes ...string) *XmlConverter
func (*XmlConverter) CanDecode ¶ added in v0.2.1
func (c *XmlConverter) CanDecode(o interface{}, mediaType MediaType) bool
func (*XmlConverter) CanEncode ¶ added in v0.2.1
func (c *XmlConverter) CanEncode(o interface{}, mediaType MediaType) bool
func (*XmlConverter) CreateDecoder ¶ added in v0.2.1
func (c *XmlConverter) CreateDecoder(r io.Reader) Decoder
func (*XmlConverter) CreateEncoder ¶ added in v0.2.1
func (c *XmlConverter) CreateEncoder(w io.Writer) Encoder
type XmlDecoder ¶ added in v0.2.1
type XmlDecoder struct {
// contains filtered or unexported fields
}
func (*XmlDecoder) Decode ¶ added in v0.2.1
func (c *XmlDecoder) Decode(result interface{}) (int64, error)
type XmlEncoder ¶ added in v0.2.1
type XmlEncoder struct {
// contains filtered or unexported fields
}
func (*XmlEncoder) Encode ¶ added in v0.2.1
func (c *XmlEncoder) Encode(i interface{}) (int64, error)
type YamlConverter ¶ added in v0.2.3
type YamlConverter struct {
BaseConverter
}
func NewYamlConverter ¶ added in v0.2.3
func NewYamlConverter() *YamlConverter
func (*YamlConverter) CanDecode ¶ added in v0.2.3
func (c *YamlConverter) CanDecode(o interface{}, mediaType MediaType) bool
func (*YamlConverter) CanEncode ¶ added in v0.2.3
func (c *YamlConverter) CanEncode(o interface{}, mediaType MediaType) bool
func (*YamlConverter) CreateDecoder ¶ added in v0.2.3
func (c *YamlConverter) CreateDecoder(r io.Reader) Decoder
func (*YamlConverter) CreateEncoder ¶ added in v0.2.3
func (c *YamlConverter) CreateEncoder(w io.Writer) Encoder
type YamlDecoder ¶ added in v0.2.3
type YamlDecoder struct {
// contains filtered or unexported fields
}
func (*YamlDecoder) Decode ¶ added in v0.2.3
func (c *YamlDecoder) Decode(result interface{}) (int64, error)
type YamlEncoder ¶ added in v0.2.3
type YamlEncoder struct {
// contains filtered or unexported fields
}
func (*YamlEncoder) Encode ¶ added in v0.2.3
func (c *YamlEncoder) Encode(i interface{}) (int64, error)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.