Documentation
¶
Index ¶
- Constants
- Variables
- type BackoffManager
- type BceError
- type ContentConfig
- type Decoder
- type Encoder
- type FastClient
- type FastHTTPClient
- type HTTPClient
- type Interface
- type NeutronError
- type NeutronErrorDetail
- type NoBackoff
- type PatchType
- type QueryCriteria
- type RESTClient
- type Request
- func (r *Request) BaseURL(baseURL *url.URL) *Request
- func (r *Request) Body(obj interface{}) *Request
- func (r *Request) ClientTimeout(d time.Duration) *Request
- func (r *Request) Context(ctx context.Context) *Request
- func (r *Request) Criteria(criteria QueryCriteria) *Request
- func (r *Request) Do() Result
- func (r *Request) GetParams() url.Values
- func (r *Request) Header() http.Header
- func (r *Request) Host() string
- func (r *Request) Namespace(namespace string) *Request
- func (r *Request) Param(paramName, s string) *Request
- func (r *Request) Resource(resource string) *Request
- func (r *Request) SetHeader(key string, values ...string) *Request
- func (r *Request) SetHost(host string) *Request
- func (r *Request) Timeout(d time.Duration) *Request
- func (r *Request) URL() *url.URL
- func (r *Request) Verb() string
- type ResponseWrapper
- type Result
- type Serializer
- type StatusError
Constants ¶
const ( BackendTypeInternal = "internal" BackendTypeK8s = "k8s" BackendTypeBce = "cloud" BackendTypeOpenstack = "openstack" HeaderKeyConnection = "Connection" HeaderValueConnectionClose = "close" HeaderValueConnectionKeepAlive = "Keep-Alive" HeaderKeyKeepAlive = "Keep-Alive" HeaderValueKeepAliveDefault = "timeout=5, max=100" )
const (
DefaultServerTimeout = 10
)
Variables ¶
var ( // DefaultInternalValidAuthTokens do internal auth verification DefaultInternalValidAuthTokens = []string{defaultInternalAuthToken} )
Functions ¶
This section is empty.
Types ¶
type BackoffManager ¶
type BceError ¶
type BceError struct { Code string `json:"code"` Message string `json:"message"` RequestID string `json:"requestId"` }
BceError xxx
type ContentConfig ¶
type ContentConfig struct { // AcceptContentTypes specifies the types the client will accept and is optional. // If not set, ContentType will be used to define the Accept header AcceptContentTypes string // ContentType specifies the wire format used to communicate with the server. // This value will be set as the Accept header on requests made to the server, and // as the default content type on any object sent to the server. If not set, // "application/json" is used. ContentType string // BackendType xxx BackendType string // Connection specifies the Connection header Connection string // Connection specifies the KeepAlive header KeepAlive string ClientTimeout time.Duration }
ContentConfig contains settings that affect how objects are transformed when sent to the server.
type Decoder ¶
type Decoder interface { // Decode attempts to deserialize the provided data using either the innate typing of the scheme or the // default kind, group, and version provided. It returns a decoded object as well as the kind, group, and // version from the serialized data, or an error. If into is non-nil, it will be used as the target type // and implementations may choose to use it rather than reallocating an object. However, the object is not // guaranteed to be populated. The returned object is not guaranteed to match into. If defaults are // provided, they are applied to the data by default. If no defaults or partial defaults are provided, the // type of the into may be used to guide conversion decisions. Decode(data []byte, into interface{}) error }
Decoder attempt to load an object from data.
type Encoder ¶
type Encoder interface { // Encode writes an object to a stream. Implementations may return errors if the versions are // incompatible, or if no conversion is defined. Encode(obj interface{}, w io.Writer) error }
Encoder write objects to a serialized form
type FastClient ¶
type FastClient struct {
// contains filtered or unexported fields
}
func NewFastClient ¶
func NewFastClient(host string) *FastClient
type FastHTTPClient ¶
FastHTTPClient is an interface for testing a request object.
type HTTPClient ¶
HTTPClient is an interface for testing a request object.
type Interface ¶
type Interface interface { Verb(verb string) *Request Post() *Request Put() *Request Patch(pt PatchType) *Request Get() *Request Delete() *Request }
Interface xxx
type NeutronError ¶
type NeutronError struct {
NeutronError NeutronErrorDetail `json:"NeutronError"`
}
NeutronError xxx
type NeutronErrorDetail ¶
type NeutronErrorDetail struct { Message string `json:"message"` Type string `json:"type"` Detail string `json:"detail"` }
NeutronErrorDetail xxx
type NoBackoff ¶
type NoBackoff struct { }
NoBackoff is a stub implementation, can be used for mocking or else as a default.
func (*NoBackoff) CalculateBackoff ¶
type PatchType ¶
type PatchType string
PatchType is the type of constants to support HTTP PATCH utilized by both the client and server that didn't make sense for a whole package to be dedicated to.
const ( // JSONPatchType defines a JSON document structure for expressing a sequence // of operations to apply to a JavaScript Object Notation (JSON) document. // See RFC 6902 (https://www.rfc-editor.org/rfc/rfc6902.txt) or // Jsonpatch (http://jsonpatch.com/) for more details. JSONPatchType PatchType = "application/json-patch+json" // MergePatchType defines the JSON merge patch format and processing rules. // See RFC 7386 (https://www.rfc-editor.org/rfc/rfc7386.txt) MergePatchType PatchType = "application/merge-patch+json" // StrategicMergePatchType xxx StrategicMergePatchType PatchType = "application/strategic-merge-patch+json" )
type QueryCriteria ¶
type QueryCriteria interface { AddCondition(key, value string) QueryCriteria Value() url.Values ReadFromRequest(r *http.Request) QueryCriteria }
func NewQueryCriteria ¶
func NewQueryCriteria() QueryCriteria
type RESTClient ¶
type RESTClient struct { // Set specific behavior of the client. If not set http.DefaultClient will be used. Client *http.Client // contains filtered or unexported fields }
RESTClient imposes common API conventions. The baseURL is expected to point to an HTTP or HTTPS path that is the parent of one or more resources. The server should return a decodable API resource object, or an error.FinalError object which contains information about the reason for any failure.
Most consumers should use client.New() to get a Kubernetes API client.
func NewRESTClient ¶
func NewRESTClient(baseURL *url.URL, version string, config ContentConfig, client *http.Client) (*RESTClient, error)
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.
func (*RESTClient) APIVersion ¶
func (c *RESTClient) APIVersion() string
APIVersion returns the APIVersion this RESTClient is expected to use.
func (*RESTClient) Delete ¶
func (c *RESTClient) Delete() *Request
Delete begins a DELETE request. Short for c.Verb("DELETE").
func (*RESTClient) Get ¶
func (c *RESTClient) Get() *Request
Get begins a GET request. Short for c.Verb("GET").
func (*RESTClient) Patch ¶
func (c *RESTClient) Patch(pt PatchType) *Request
Patch begins a PATCH request. Short for c.Verb("Patch").
func (*RESTClient) Post ¶
func (c *RESTClient) Post() *Request
Post begins a POST request. Short for c.Verb("POST").
func (*RESTClient) Put ¶
func (c *RESTClient) Put() *Request
Put begins a PUT request. Short for c.Verb("PUT").
func (*RESTClient) Verb ¶
func (c *RESTClient) Verb(verb string) *Request
Verb begins a request with a verb (GET, POST, PUT, DELETE).
Example usage of RESTClient's request building interface: c, err := rest.NewRESTClient(...) if err != nil { ... } resp, err := c.Verb("GET").
Path("pods"). Timeout(10*time.Second). Do()
if err != nil { ... } list, ok := resp.(*api.PodList)
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(client HTTPClient, verb string, baseURL *url.URL, version string, content ContentConfig, backoff BackoffManager, timeout time.Duration) *Request
NewRequest creates a new request helper object for accessing runtime.Objects on a server. TODO: add client-side throttle & backoff like k8s TODO: more serializers
func (*Request) Body ¶
Body makes the request use obj as the body. Optional. If obj is a string, try to read a file of that name. If obj is a []byte, send it directly. If obj is an io.Reader, use it directly. If obj is a object, marshal it with json, and set Content-Type header. TODO: more serializers
func (*Request) ClientTimeout ¶
ClientTimeout
func (*Request) Context ¶
Context adds a context to the request. Contexts are only used for timeouts, deadlines, and cancellations.
func (*Request) Criteria ¶
func (r *Request) Criteria(criteria QueryCriteria) *Request
Criteria adds special parameters into this request
func (*Request) Do ¶
Do formats and executes the request. Returns a Result object for easy response processing.
Error type:
- If the request can't be constructed, or an error happened earlier while building its arguments: *RequestConstructionError
- If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError
- http.Client.Do errors are returned directly.
func (*Request) Namespace ¶
Namespace applies the namespace scope to a request (<resource>/[ns/<namespace>/]<name>)
func (*Request) Resource ¶
Resource sets the resource to access (<resource>/[ns/<namespace>/]<name>)
type ResponseWrapper ¶
type ResponseWrapper interface { DoRaw() ([]byte, error) Stream() (io.ReadCloser, error) }
ResponseWrapper is an interface for getting a response. The response may be either accessed as a raw data (the whole output is put into memory) or as a stream.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result contains the result of calling Request.Do().
func (Result) Error ¶
Error returns the error executing the request, nil if no error occurred. If the returned object is of type Status and has Status != StatusSuccess, the additional information in Status will be used to enrich the error. See the Request.Do() comment for what errors you might get.
func (Result) GetStatusCode ¶
func (Result) Into ¶
Into stores the result into obj, if possible. If obj is nil it is ignored. If the returned object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.
func (Result) StatusCode ¶
StatusCode returns the HTTP status code of the request. (Only valid if no error was returned.)
type Serializer ¶
Serializer is the core interface for transforming objects into a serialized format and back. Implementations may choose to perform conversion of the object, but no assumptions should be made.
type StatusError ¶
StatusError xxx
func (StatusError) Error ¶
func (e StatusError) Error() string
Error implements the Error interface.