http

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinRetryDelay determines the minimum retry interval in case
	// of an error.
	MinRetryDelay = 100 * time.Millisecond

	// DefaultMinDelay is the default minimum re-downloading
	// interval in case of a previously successful download.
	DefaultMinDelay = 60 * time.Second

	// DefaultMaxDelay is the default maximum re-downloading
	// interval in case of a previously successful download.
	DefaultMaxDelay = 120 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

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

Loader downloads a bundle over HTTP. If started, it downloads the bundle periodically until closed.

func New

func New(o *opa.OPA) *Loader

New constructs a new HTTP loader periodically downloading a bundle over HTTP.

func (*Loader) Close

func (l *Loader) Close()

Close stops the downloading, releasing all resources.

func (*Loader) Init

func (l *Loader) Init() (*Loader, error)

Init initializes the loader after its construction and configuration. If invalid config, will return ErrInvalidConfig.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) error

Load downloads the bundle from a remote location and installs it. The possible returned errors are ErrInvalidBundle (in case of an error in downloading or opening the bundle) and the ones SetPolicyData of OPA returns.

func (*Loader) Start

func (l *Loader) Start(ctx context.Context) error

Start starts the periodic downloads, blocking until the first successful download. If cancelled, will return context.Cancelled.

func (*Loader) WithClient

func (l *Loader) WithClient(client *http.Client) *Loader

WithClient configures the HTTP client to use. If not configured, http.DefaultClient is used.

func (*Loader) WithErrorLogger

func (l *Loader) WithErrorLogger(logger func(error)) *Loader

WithErrorLogger configures an error logger invoked with all the errors.

func (*Loader) WithInterval

func (l *Loader) WithInterval(min, max time.Duration) *Loader

WithInterval configures the minimum and maximum delay between bundle downloads.

func (*Loader) WithPrepareRequest

func (l *Loader) WithPrepareRequest(prepare func(*http.Request) error) *Loader

WithPrepareRequest configures a handler to customize the HTTP requests before their sending. The HTTP request is not modified after the handle invocation.

func (*Loader) WithURL

func (l *Loader) WithURL(url string) *Loader

WithURL configures the URL to download the bundle from.

Jump to

Keyboard shortcuts

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