rest

package
v0.0.0-...-f79c7ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPMethodPost = iota + 1
	HTTPMethodPut
	HTTPMethodGet
	HTTPMethodDelete
)

Valid HTTP methods.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	User     string
	Password string
}

BasicAuth holds the basic authentication information.

type CDCRESTClient

type CDCRESTClient struct {

	// Client is a wrapped http client.
	Client *httputil.Client
	// contains filtered or unexported fields
}

CDCRESTClient defines a TiCDC RESTful client

func CDCRESTClientFromConfig

func CDCRESTClientFromConfig(config *Config) (*CDCRESTClient, error)

CDCRESTClientFromConfig creates a CDCRESTClient from specific config items.

func NewCDCRESTClient

func NewCDCRESTClient(
	baseURL *url.URL,
	versionedAPIPath string,
	client *httputil.Client,
	basicAuth BasicAuth,
	params url.Values,
) (*CDCRESTClient, error)

NewCDCRESTClient creates a new CDCRESTClient.

func (*CDCRESTClient) Delete

func (c *CDCRESTClient) Delete() *Request

Delete begins a DELETE request. Short for c.Method(HTTPMethodDelete).

func (*CDCRESTClient) Get

func (c *CDCRESTClient) Get() *Request

Get begins a GET request. Short for c.Method(HTTPMethodGet).

func (*CDCRESTClient) Method

func (c *CDCRESTClient) Method(method HTTPMethod) *Request

Method begins a request with a http method (GET, POST, PUT, DELETE).

func (*CDCRESTClient) Post

func (c *CDCRESTClient) Post() *Request

Post begins a POST request. Short for c.Method(HTTPMethodPost).

func (*CDCRESTClient) Put

func (c *CDCRESTClient) Put() *Request

Put begins a PUT request. Short for c.Method(HTTPMethodPut).

type CDCRESTInterface

type CDCRESTInterface interface {
	Method(method HTTPMethod) *Request
	Post() *Request
	Put() *Request
	Get() *Request
	Delete() *Request
}

CDCRESTInterface includes a set of operations to interact with TiCDC RESTful apis.

type Config

type Config struct {
	// Host must be a host string, a host:port pair, or a URL to the base of the cdc server.
	Host string
	// APIPath is a sub-path that points to an API root.
	APIPath string
	// Credential holds the security Credential used for generating tls config.
	Credential *security.Credential

	// API verion
	Version string
	// Extra query parameters
	Values url.Values
	// contains filtered or unexported fields
}

Config holds the common attributes that can be passed to a cdc REST client

type HTTPMethod

type HTTPMethod int

HTTPMethod represents HTTP method.

func (HTTPMethod) String

func (h HTTPMethod) String() string

String implements Stringer.String.

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request allows for building up a request to cdc server in a chained fasion. Any errors are stored until the end of your call, so you only have to check once.

func NewRequest

func NewRequest(c *CDCRESTClient) *Request

NewRequest creates a new request.

func (*Request) Do

func (r *Request) Do(ctx context.Context) (res *Result)

Do formats and executes the request.

func (*Request) URL

func (r *Request) URL() *url.URL

URL returns the current working URL.

func (*Request) WithBackoffBaseDelay

func (r *Request) WithBackoffBaseDelay(delay time.Duration) *Request

WithBackoffBaseDelay specifies the base backoff sleep duration.

func (*Request) WithBackoffMaxDelay

func (r *Request) WithBackoffMaxDelay(delay time.Duration) *Request

WithBackoffMaxDelay specifies the maximum backoff sleep duration.

func (*Request) WithBody

func (r *Request) WithBody(obj interface{}) *Request

WithBody makes http request use obj as its body. only supports two types now:

  1. io.Reader
  2. type which can be json marshalled

func (*Request) WithHeader

func (r *Request) WithHeader(key string, values ...string) *Request

WithHeader set the http request header.

func (*Request) WithMaxRetries

func (r *Request) WithMaxRetries(maxRetries uint64) *Request

WithMaxRetries specifies the maximum times a request will retry.

func (*Request) WithMethod

func (r *Request) WithMethod(method HTTPMethod) *Request

WithMethod sets the method this request will use.

func (*Request) WithParam

func (r *Request) WithParam(name, value string) *Request

WithParam sets the http request query params.

func (*Request) WithPrefix

func (r *Request) WithPrefix(segments ...string) *Request

WithPrefix adds segments to the beginning of request url.

func (*Request) WithTimeout

func (r *Request) WithTimeout(d time.Duration) *Request

WithTimeout specifies overall timeout of a request.

func (*Request) WithURI

func (r *Request) WithURI(uri string) *Request

WithURI sets the server relative URI.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result contains the result of calling Request.Do().

func (Result) Error

func (r Result) Error() error

Error returns the request error.

func (Result) Into

func (r Result) Into(obj interface{}) error

Into stores the http response body into obj.

func (Result) Raw

func (r Result) Raw() ([]byte, error)

Raw returns the raw result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL