session

package
v9.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 17 Imported by: 13

Documentation

Overview

Package session provides the base secure http client and request management for akamai apis

Index

Constants

View Source
const (
	// Version is the client version
	Version = "9.0.0"
)

Variables

View Source
var (
	// ErrInvalidArgument is returned when invalid number of arguments were supplied to a function
	ErrInvalidArgument = errors.New("invalid arguments provided")
	// ErrMarshaling represents marshaling error
	ErrMarshaling = errors.New("marshaling input")
	// ErrUnmarshaling represents unmarshaling error
	ErrUnmarshaling = errors.New("unmarshaling output")
)

Functions

func CloseResponseBody added in v9.1.0

func CloseResponseBody(resp *http.Response)

CloseResponseBody closes response body

func ContextWithOptions

func ContextWithOptions(ctx context.Context, opts ...ContextOption) context.Context

ContextWithOptions adds request-specific options to the context This log debugs the request using only the provided log

func GetRetryableLogger added in v9.1.0

func GetRetryableLogger(log log.Interface) retryablehttp.LeveledLogger

GetRetryableLogger returns wrapper retryablehttp.LeveledLogger for log.Interface

Types

type ContextOption

type ContextOption func(*contextOptions)

ContextOption are options on the context

func WithContextHeaders

func WithContextHeaders(h http.Header) ContextOption

WithContextHeaders sets the context headers

func WithContextLog

func WithContextLog(l log.Interface) ContextOption

WithContextLog provides a context specific logger

type Option

type Option func(*session)

Option defines a client option

func WithClient

func WithClient(client *http.Client) Option

WithClient creates a client using the specified http.Client

func WithHTTPTracing

func WithHTTPTracing(trace bool) Option

WithHTTPTracing sets the request and response dump for debugging

func WithLog

func WithLog(l log.Interface) Option

WithLog sets the log interface for the client

func WithRequestLimit

func WithRequestLimit(requestLimit int) Option

WithRequestLimit sets the maximum number of API calls that the provider will make per second.

func WithRetries added in v9.1.0

func WithRetries(conf RetryConfig) Option

WithRetries configures the HTTP client to automatically retry failed GET requests

func WithSigner

func WithSigner(signer edgegrid.Signer) Option

WithSigner sets the request signer for the session

func WithUserAgent

func WithUserAgent(u string) Option

WithUserAgent sets the user agent string for the client

type RetryConfig added in v9.1.0

type RetryConfig struct {
	RetryMax          int
	RetryWaitMin      time.Duration
	RetryWaitMax      time.Duration
	ExcludedEndpoints []string
}

RetryConfig struct contains http retry configuration.

ExcludedEndpoints field is a list of shell patterns. The pattern syntax is:

pattern:
	{ term }
term:
	'*'         matches any sequence of non-/ characters
	'?'         matches any single non-/ character
	'[' [ '^' ] { character-range } ']'
	            character class (must be non-empty)
	c           matches character c (c != '*', '?', '\\', '[')
	'\\' c      matches character c

character-range:
	c           matches character c (c != '\\', '-', ']')
	'\\' c      matches character c
	lo '-' hi   matches character c for lo <= c <= hi

func NewRetryConfig added in v9.1.0

func NewRetryConfig() RetryConfig

NewRetryConfig creates a new retry config with default settings.

type Session

type Session interface {
	// Exec will sign and execute a request returning the response
	// The response body will be unmarshaled in to out
	// Optionally the in value will be marshaled into the body
	Exec(r *http.Request, out interface{}, in ...interface{}) (*http.Response, error)

	// Sign will only sign a request, this is useful for circumstances
	// when the caller wishes to manage the http client
	Sign(r *http.Request) error

	// Log returns the logging interface for the session
	// If provided all debugging will output to this log interface
	Log(ctx context.Context) log.Interface

	// Client return the session http client
	Client() *http.Client
}

Session is the interface that is used by the pa This allows the client itself to be more extensible and readily testable, ets.

func Must

func Must(sess Session, err error) Session

Must is a helper that will result in a panic if an error is returned ex. sess := Must(New())

func New

func New(opts ...Option) (Session, error)

New returns a new session

Jump to

Keyboard shortcuts

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