rest

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeResponse

func DecodeResponse(resp *http.Response) (map[string]interface{}, error)

DecodeResponse decodes response body into a map.

func DefaultServerURL

func DefaultServerURL(host, apiPrefix string, defaultTLS bool) (*url.URL, string, error)

DefaultServerURL converts a host, host:port, or URL string to the default base server API path to use with a Client at a given API version following the standard conventions for an HTTP API.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

Client defines a common JAC CMS API client.

func NewClient

func NewClient(cfg *ClientConfig) (*Client, error)

NewClient returns a API server client, which is an HTTP client.

func (*Client) Verb

func (c *Client) Verb(verb string) *Request

Verb receives a verb which indicates what HTTP method should be invoked.

type ClientConfig

type ClientConfig struct {
	// Host must be a host string, a host:port pair, or a URL to the base of the apiserver.
	Host string

	// APIPath is a sub-path that points to an API root.
	APIPath string

	// ContentConfig contains settings that affect how objects are transformed when
	// sent to the server.
	ContentConfig *ContentConfig

	// BearerToken is needed when server requires Bearer authentication (not refreshable).
	BearerToken string

	// BearerTokenTag defines what tag name to be used.
	// If not set, default 'bearer' will be set.
	BearerTokenTag string

	TLSClientConfig *TLSClientConfig

	// The maximum length of time to wait before giving up on a server request. A value of zero means no timeout.
	Timeout time.Duration
}

ClientConfig defines a config for creating a REST client.

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 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
}

ContentConfig contains settings that affect how objects are transformed when sent to the server.

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 *Client) *Request

NewRequest returns an new Request.

func (*Request) Body

func (r *Request) Body(body map[string]string) *Request

Body receives body that will be used to make POST call.

func (*Request) Do

func (r *Request) Do() (*http.Response, error)

Do does the real dirty job.

func (*Request) Selectors

func (r *Request) Selectors(selectors map[string]string) *Request

Selectors receives selectors that will be used to make query string.

func (*Request) Verb

func (r *Request) Verb(verb string) *Request

Verb receives a verb that indicates which HTTP method should be invoked.

type TLSClientConfig

type TLSClientConfig struct {
	// Server should be accessed without verifying the TLS certificate. For testing only.
	Insecure bool

	// ServerName is passed to the server for SNI and is used in the client to check server
	// certificates against. If ServerName is empty, the hostname used to contact the
	// server is used.
	ServerName string

	// Server requires TLS client certificate authentication
	CertFile string

	// Server requires TLS client certificate authentication
	KeyFile string

	// Trusted root certificates for server
	CAFile string

	// CertData holds PEM-encoded bytes (typically read from a client certificate file).
	// CertData takes precedence over CertFile
	CertData []byte

	// KeyData holds PEM-encoded bytes (typically read from a client certificate key file).
	// KeyData takes precedence over KeyFile
	KeyData []byte

	// CAData holds PEM-encoded bytes (typically read from a root certificates bundle).
	// CAData takes precedence over CAFile
	CAData []byte
}

TLSClientConfig contains settings to enable transport layer security (TLS).

func (TLSClientConfig) GoString

func (c TLSClientConfig) GoString() string

GoString implements fmt.GoStringer and sanitizes sensitive fields of TLSClientConfig to prevent accidental leaking via logs.

func (TLSClientConfig) String

func (c TLSClientConfig) String() string

String implements fmt.Stringer and sanitizes sensitive fields of TLSClientConfig to prevent accidental leaking via logs.

Jump to

Keyboard shortcuts

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