restapi

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// UserAgent specifies the HTTP user-agent string for the SDK
	// clients.
	UserAgent = "privx-sdk-go"
)

Variables

This section is empty.

Functions

func ErrorFromResponse

func ErrorFromResponse(r *http.Response, responseBody []byte) error

ErrorFromResponse creates an error value from the REST API error response.

Types

type Authorizer

type Authorizer interface {
	AccessToken() (string, error)
	Cookie() string
}

Authorizer provides access token for REST API client

type CURL

type CURL interface {
	// Query defines URI parameters of the request
	Query(interface{}) CURL
	// Header defines request header
	Header(string, string) CURL
	// Status evalutes the request
	Status(...int) (http.Header, error)
	Get(interface{}) (http.Header, error)
	Put(interface{}, ...interface{}) (http.Header, error)
	Post(interface{}, ...interface{}) (http.Header, error)
	Delete(...interface{}) (http.Header, error)
	Fetch() ([]byte, error)
	Download(string) error
}

CURL is HTTP request

type Certificate

type Certificate struct {
	X509 *x509.Certificate
}

Certificate specifies a trusted CA certificate for the REST endpoint.

func (Certificate) MarshalText

func (cert Certificate) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Certificate) UnmarshalText

func (cert *Certificate) UnmarshalText(text []byte) error

UnmarshalText unmarshals certificate from a configuration file PEM block.

type Connector

type Connector interface {
	// URL creates a request/response session
	URL(string, ...interface{}) CURL
}

Connector is HTTP connector for api

func New

func New(opts ...Option) Connector

New creates an instance of HTTP client

type ErrorDetail

type ErrorDetail struct {
	ErrorCode    string `json:"error_code"`
	ErrorMessage string `json:"error_message,omitempty"`
	Property     string `json:"property,omitempty"`
}

ErrorDetail contains detailed error information, linked with the error response.

type ErrorResponse

type ErrorResponse struct {
	ErrorCode    string        `json:"error_code"`
	ErrorMessage string        `json:"error_message,omitempty"`
	Property     string        `json:"property,omitempty"`
	Details      []ErrorDetail `json:"details,omitempty"`
}

ErrorResponse contains REST endpoint error response information.

type Option

type Option func(*tClient) *tClient

Option is configuration applied to the client

func Auth

func Auth(auth Authorizer) Option

Auth setup access token provider for api

func BaseURL

func BaseURL(endpoint string) Option

BaseURL defines a target PrivX server and possible path prefix

func Retry

func Retry(n int) Option

Retry HTTP I/O multiple times before failure

func TrustAnchor

func TrustAnchor(cert *x509.Certificate) Option

TrustAnchor setups X509 certificates to trust TLS connections

func UseConfigFile

func UseConfigFile(path string) Option

UseConfigFile setup rest client from toml file

func UseEnvironment

func UseEnvironment() Option

UseEnvironment setups rest client using environment variables

func Verbose

func Verbose() Option

Verbose enables debug-level logging

type WriteCounter added in v0.6.0

type WriteCounter struct {
	Total uint64
}

WriteCounter count bytes for a file download

func (*WriteCounter) Write added in v0.6.0

func (wc *WriteCounter) Write(p []byte) (int, error)

Write increments the counter by the size of the bytes written into it

Jump to

Keyboard shortcuts

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