Documentation ¶
Index ¶
- Constants
- func HeaderFilterFlags(content string) string
- func NewDefaultHeader() http.Header
- type AuthType
- type RESTClient
- func (c *RESTClient) Delete(path string) *Request
- func (c *RESTClient) Get(path string) *Request
- func (c *RESTClient) Group(url 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) SetTimeout(t time.Duration) *RESTClient
- type 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 (c *Request) SetRequestRate(rate float64, capacity int64) *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 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) 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(url 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("goat", "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) SetTimeout ¶
func (c *RESTClient) SetTimeout(t time.Duration) *RESTClient
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) SetRequestRate ¶
SetRequestRate 设置请求速率, rate: 速率, capacity: 容量(控制并发量)
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