http

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 9 Imported by: 0

README

http

Contains functions for managing HTTP requests. Substation follows these rules across every application:

  • HTTP clients are always retryable clients from this package
  • For AWS deployments, HTTP clients enable AWS X-Ray

Documentation

Index

Constants

View Source
const HTTPInvalidPayload = errors.Error("HTTPInvalidPayload")

HTTPInvalidPayload is returned by HTTP.Post when it receives an unexpected payload interface.

View Source
const MaxBytesPerPayload = 1000 * 1000

MaxBytesPerPayload is the maxmimum size of an aggregated HTTP payload. Substation uses a constant max size of 1MB.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

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

Aggregate stores multiple strings in a newline-delimited payload. This structure can be used when downstream logging systems (e.g., Splunk, Sumo Logic) accept multiple events in a single HTTP POST request.

func (*Aggregate) Add

func (a *Aggregate) Add(data string) bool

Add adds string data to the aggregated payload and returns a boolean that describes if the addition was successful. If the method returns false, then the maximum size of the aggregated payload was reached and no more data can be added; if this happens, then the caller must retrieve the aggregated payload, send it to its destination, and create a new Aggregate for storing the failed data.

func (*Aggregate) Count

func (a *Aggregate) Count() int

Count returns the number of strings inside the aggregated payload.

func (*Aggregate) Get

func (a *Aggregate) Get() string

Get returns the aggregated payload.

func (*Aggregate) New

func (a *Aggregate) New()

New initializes a new Aggregate.

func (*Aggregate) Peek

func (a *Aggregate) Peek(n int) []string

Peek returns the first N strings inside the aggregated payload. This method can be used to check the content of the payload before POSTing it to a desination.

func (*Aggregate) Size

func (a *Aggregate) Size() int

Size returns the byte size of the aggregated payload.

type HTTP

type HTTP struct {
	Client *retryablehttp.Client
}

HTTP wraps a retryable HTTP client.

func (*HTTP) EnableXRay

func (h *HTTP) EnableXRay()

EnableXRay replaces the standard retryable HTTP client with an AWS XRay client. This method can be used when making HTTP calls on AWS infrastructure and should be enabled by looking for the environment variable "AWS_XRAY_DAEMON_ADDRESS".

func (*HTTP) Get

func (h *HTTP) Get(ctx context.Context, url string) (*http.Response, error)

Get is a context-aware convenience function for making GET requests.

func (*HTTP) IsEnabled

func (h *HTTP) IsEnabled() bool

IsEnabled identifies if the HTTP client is enabled and ready to use. This method can be used for lazy loading the client.

func (*HTTP) Post

func (h *HTTP) Post(ctx context.Context, url string, payload interface{}, headers ...Header) (resp *http.Response, err error)

Post is a context-aware convenience function for making POST requests. This method optionally supports custom headers.

func (*HTTP) Setup

func (h *HTTP) Setup()

Setup creates a retryable HTTP client.

type Header struct {
	Key   string
	Value string
}

Header contains a single HTTP header that can be passed to HTTP.Post. Multiple headers can be passed to HTTP.Post as a slice.

Jump to

Keyboard shortcuts

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