utils

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2017 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HTTPUserAgent = "Courier/vDev"
)

Functions

func AddURLPath added in v0.2.0

func AddURLPath(urlStr string, paths ...string) (string, error)

func CleanString added in v0.2.0

func CleanString(s string) string

CleanString removes any control characters from the passed in string

func DecodeUTF8

func DecodeUTF8(bytes []byte) string

DecodeUTF8 is equivalent to .decode('utf-8', 'ignore') in Python

func GetHTTPClient

func GetHTTPClient() *http.Client

GetHTTPClient returns the shared HTTP client used by all Courier threads

func GetInsecureHTTPClient added in v0.2.0

func GetInsecureHTTPClient() *http.Client

GetInsecureHTTPClient returns the shared HTTP client used by all Courier threads

func JoinNonEmpty

func JoinNonEmpty(delim string, strings ...string) string

JoinNonEmpty takes a vararg of strings and return the join of all the non-empty strings with a delimiter between them

func MapAsJSON

func MapAsJSON(m map[string]string) []byte

MapAsJSON serializes the given map as a JSON string

func PutS3File

func PutS3File(s3Client s3iface.S3API, bucket string, path string, contentType string, contents []byte) (string, error)

PutS3File writes the passed in file to the bucket with the passed in content type

func StringArrayContains

func StringArrayContains(s []string, e string) bool

StringArrayContains returns whether a given string array contains the given element

func TestS3

func TestS3(s3Client s3iface.S3API, bucket string) error

TestS3 tests whether the passed in s3 client is properly configured and the passed in bucket is accessible

Types

type NullMap

type NullMap struct {
	Map   map[string]interface{}
	Valid bool
}

NullMap is a one level deep dictionary that is represented as JSON in the database

func NewNullMap added in v0.8.0

func NewNullMap(validMap map[string]interface{}) NullMap

NewNullMap creates a new null map with the passed in map

func (*NullMap) MarshalJSON

func (n *NullMap) MarshalJSON() ([]byte, error)

MarshalJSON decodes our dictionary from the passed in bytes

func (*NullMap) Scan

func (n *NullMap) Scan(src interface{}) error

Scan implements the Scanner interface for decoding from a database

func (*NullMap) UnmarshalJSON

func (n *NullMap) UnmarshalJSON(data []byte) error

UnmarshalJSON sets our dict from the passed in data

func (*NullMap) Value

func (n *NullMap) Value() (driver.Value, error)

Value implements the driver Valuer interface

type RequestResponse added in v0.2.0

type RequestResponse struct {
	Method     string
	URL        string
	Status     RequestResponseStatus
	StatusCode int
	Request    string
	Response   string
	Body       []byte
	Elapsed    time.Duration
}

RequestResponse represents both the outgoing request and response for a particular URL/method/body

func MakeHTTPRequest

func MakeHTTPRequest(req *http.Request) (*RequestResponse, error)

MakeHTTPRequest fires the passed in http request, returning any errors encountered. RequestResponse is always set regardless of any errors being set

func MakeInsecureHTTPRequest added in v0.2.0

func MakeInsecureHTTPRequest(req *http.Request) (*RequestResponse, error)

MakeInsecureHTTPRequest fires the passed in http request against a transport that does not validate SSL certificates.

type RequestResponseStatus added in v0.2.0

type RequestResponseStatus string

RequestResponseStatus represents the status of a WebhookRequeset

const (
	// RRStatusSuccess represents that the webhook was successful
	RRStatusSuccess RequestResponseStatus = "S"

	// RRConnectionFailure represents that the webhook had a connection failure
	RRConnectionFailure RequestResponseStatus = "F"

	// RRStatusFailure represents that the webhook had a non 2xx status code
	RRStatusFailure RequestResponseStatus = "E"
)

Jump to

Keyboard shortcuts

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