NewRESTClient creates a new RESTClient. This client performs generic REST functions such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and decoding of responses from the server.
(baseURL *url.URL, versionedAPIPath string, config ContentConfig, maxQPS float32, maxBurst int, rateLimiter flowcontrol.RateLimiter, client *http.Client)
| 92 | // such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and |
| 93 | // decoding of responses from the server. |
| 94 | func NewRESTClient(baseURL *url.URL, versionedAPIPath string, config ContentConfig, maxQPS float32, maxBurst int, rateLimiter flowcontrol.RateLimiter, client *http.Client) (*RESTClient, error) { |
| 95 | base := *baseURL |
| 96 | if !strings.HasSuffix(base.Path, "/") { |
| 97 | base.Path += "/" |
| 98 | } |
| 99 | base.RawQuery = "" |
| 100 | base.Fragment = "" |
| 101 | |
| 102 | if config.GroupVersion == nil { |
| 103 | config.GroupVersion = &schema.GroupVersion{} |
| 104 | } |
| 105 | if len(config.ContentType) == 0 { |
| 106 | config.ContentType = "application/json" |
| 107 | } |
| 108 | serializers, err := createSerializers(config) |
| 109 | if err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | |
| 113 | var throttle flowcontrol.RateLimiter |
| 114 | if maxQPS > 0 && rateLimiter == nil { |
| 115 | throttle = flowcontrol.NewTokenBucketRateLimiter(maxQPS, maxBurst) |
| 116 | } else if rateLimiter != nil { |
| 117 | throttle = rateLimiter |
| 118 | } |
| 119 | return &RESTClient{ |
| 120 | base: &base, |
| 121 | versionedAPIPath: versionedAPIPath, |
| 122 | contentConfig: config, |
| 123 | serializers: *serializers, |
| 124 | createBackoffMgr: readExpBackoffConfig, |
| 125 | Throttle: throttle, |
| 126 | Client: client, |
| 127 | }, nil |
| 128 | } |
| 129 | |
| 130 | // GetRateLimiter returns rate limier for a given client, or nil if it's called on a nil client |
| 131 | func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter { |