Documentation ¶
Index ¶
- Constants
- func HeaderFilterFlags(content string) string
- func NewDefaultHeader() http.Header
- func NewTLSConfig(certFile, keyFile, caFile string) (*tls.Config, error)
- type AuthType
- type Exception
- type ExceptionHandleFunc
- type RESTClient
- func (c *RESTClient) Clone() *RESTClient
- func (c *RESTClient) Delete(path string) *Request
- func (c *RESTClient) DisableTrace() *RESTClient
- func (c *RESTClient) EnableTrace() *RESTClient
- func (c *RESTClient) Get(path string) *Request
- func (c *RESTClient) Group(urlPath string) *RESTClient
- func (c *RESTClient) Method(verb string) *Request
- func (c *RESTClient) Patch(path string) *Request
- func (c *RESTClient) Post(path string) *Request
- func (c *RESTClient) Put(path string) *Request
- func (c *RESTClient) SetBaseURL(url string) *RESTClient
- func (c *RESTClient) SetBasicAuth(username, password string) *RESTClient
- func (c *RESTClient) SetBearerTokenAuth(token string) *RESTClient
- func (c *RESTClient) SetContentType(contentType string)
- func (c *RESTClient) SetCookie(cs ...*http.Cookie) *RESTClient
- func (c *RESTClient) SetHeader(key string, values ...string) *RESTClient
- func (c *RESTClient) SetRequestRate(rate float64, capacity int64) *RESTClient
- func (c *RESTClient) SetTLSConfig(conf *tls.Config) *RESTClient
- func (c *RESTClient) SetTimeout(t time.Duration) *RESTClient
- func (c *RESTClient) WithExceptionHandleFunc(fn ExceptionHandleFunc)
- type Request
- func (r *Request) AbsURL(p string) *Request
- func (r *Request) Body(v any) *Request
- func (r *Request) Cookie(cs ...*http.Cookie) *Request
- func (r *Request) Do(ctx context.Context) *Response
- func (r *Request) Header(key string, values ...string) *Request
- func (r *Request) Method(verb string) *Request
- func (r *Request) Param(paramName, value string) *Request
- func (r *Request) ParamBindJson(obj any) *Request
- func (r *Request) Prefix(segments ...string) *Request
- func (c *Request) SetRequestRate(rate float64, capacity int64) *Request
- func (r *Request) Suffix(segments ...string) *Request
- func (r *Request) Timeout(d time.Duration) *Request
- func (r *Request) URL(p string) *Request
- type Response
- type User
Constants ¶
const ( ACCEPT_HEADER = "Accept" CONTENT_TYPE_HEADER = "Content-Type" CONTENT_ENCODING_HEADER = "Content-Encoding" AUTHORIZATION_HEADER = "Authorization" )
Variables ¶
This section is empty.
Functions ¶
func HeaderFilterFlags ¶
func NewDefaultHeader ¶
Types ¶
type Exception ¶ added in v2.0.18
func NewException ¶ added in v2.0.18
func (*Exception) MustDecode ¶ added in v2.0.18
func (*Exception) WithDecoder ¶ added in v2.0.18
func (e *Exception) WithDecoder(decoder negotiator.Decoder) *Exception
type ExceptionHandleFunc ¶ added in v2.0.18
type RESTClient ¶
type RESTClient struct {
// contains filtered or unexported fields
}
func NewRESTClient ¶
func NewRESTClient() *RESTClient
NewRESTClient creates a new RESTClient. This client performs generic REST functions such as Get, Put, Post, and Delete on specified paths.
func (*RESTClient) Clone ¶
func (c *RESTClient) Clone() *RESTClient
func (*RESTClient) Delete ¶
func (c *RESTClient) Delete(path string) *Request
Delete begins a DELETE request. Short for c.Verb("DELETE").
func (*RESTClient) Get ¶
func (c *RESTClient) Get(path string) *Request
Get begins a GET request. Short for c.Verb("GET").
func (*RESTClient) Group ¶
func (c *RESTClient) Group(urlPath string) *RESTClient
func (*RESTClient) Method ¶
func (c *RESTClient) Method(verb string) *Request
Verb begins a request with a verb (GET, POST, PUT, DELETE).
Example usage of RESTClient's request building interface: c, err := NewRESTClient(...) if err != nil { ... } resp, err := c.Verb("GET").
Path("pods"). SelectorParam("labels", "area=staging"). Timeout(10*time.Second). Do()
if err != nil { ... } list, ok := resp.(*api.PodList)
func (*RESTClient) Patch ¶
func (c *RESTClient) Patch(path string) *Request
Patch begins a PATCH request. Short for c.Verb("Patch").
func (*RESTClient) Post ¶
func (c *RESTClient) Post(path string) *Request
Post begins a POST request. Short for c.Verb("POST").
func (*RESTClient) Put ¶
func (c *RESTClient) Put(path string) *Request
Put begins a PUT request. Short for c.Verb("PUT").
func (*RESTClient) SetBaseURL ¶
func (c *RESTClient) SetBaseURL(url string) *RESTClient
func (*RESTClient) SetBasicAuth ¶
func (c *RESTClient) SetBasicAuth(username, password string) *RESTClient
SetBasicAuth method sets the basic authentication header in the current HTTP request.
For Example:
Authorization: Basic <base64-encoded-value>
To set the header for username "go-resty" and password "welcome"
client.SetBasicAuth("mcube", "welcome")
This method overrides the credentials set by method `Client.SetBasicAuth`.
func (*RESTClient) SetBearerTokenAuth ¶
func (c *RESTClient) SetBearerTokenAuth(token string) *RESTClient
SetAuthToken method sets the auth token header(Default Scheme: Bearer) in the current HTTP request. Header example:
Authorization: Bearer <auth-token-value-comes-here>
For Example: To set bearer token BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F
client.SetBearerToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F")
This method overrides the Auth token set by method `Client.SetAuthToken`.
func (*RESTClient) SetContentType ¶
func (c *RESTClient) SetContentType(contentType string)
SetContentType set the Content-Type header of the request. application/json
func (*RESTClient) SetCookie ¶
func (c *RESTClient) SetCookie(cs ...*http.Cookie) *RESTClient
SetCookie method sets an array of cookies in the client instance. These cookies will be added to all the request raised from this client instance.
cookies := []*http.Cookie{ &http.Cookie{ Name:"key-1", Value:"This is cookie 1 value", }, &http.Cookie{ Name:"key2-2", Value:"This is cookie 2 value", }, } // Setting a cookies into client.SetCookie(cookies...)
func (*RESTClient) SetHeader ¶
func (c *RESTClient) SetHeader(key string, values ...string) *RESTClient
func (*RESTClient) SetRequestRate ¶
func (c *RESTClient) SetRequestRate(rate float64, capacity int64) *RESTClient
SetRequestRate 设置全局请求速率, rate: 速率, capacity: 容量(控制并发量)
func (*RESTClient) SetTLSConfig ¶
func (c *RESTClient) SetTLSConfig(conf *tls.Config) *RESTClient
func (*RESTClient) SetTimeout ¶
func (c *RESTClient) SetTimeout(t time.Duration) *RESTClient
func (*RESTClient) WithExceptionHandleFunc ¶ added in v2.0.18
func (c *RESTClient) WithExceptionHandleFunc(fn ExceptionHandleFunc)
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request allows for building up a request to a server in a chained fashion. Any errors are stored until the end of your call, so you only have to check once.
func NewRequest ¶
func NewRequest(c *RESTClient) *Request
NewRequest creates a new request helper object.
func (*Request) ParamBindJson ¶ added in v2.0.17
Param creates a query parameter with the given json obj to url.Values.
func (*Request) Prefix ¶
Prefix adds segments to the relative beginning to the request path. These items will be placed before the optional Namespace, Resource, or Name sections. Setting AbsPath will clear any previously set Prefix segments
func (*Request) SetRequestRate ¶
SetRequestRate 设置请求速率, rate: 速率, capacity: 容量(控制并发量)
func (*Request) Suffix ¶
Suffix appends segments to the end of the path. These items will be placed after the prefix and optional Namespace, Resource, or Name sections.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response contains the result of calling Request.Do().
func NewResponse ¶
func NewResponse(c *RESTClient) *Response
func (*Response) ContentType ¶
func (r *Response) ContentType(m negotiator.MIME) *Response
默认不设置通过Content-Type获取, 如果设定, 以设定为准