util

package
v0.0.0-...-3c45f7e Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package util provides utilities and constants used throughout the package.

Index

Constants

View Source
const (
	// Algorithm represents the algorithm and version used for signatures.
	Algorithm = "AWS4-HMAC-SHA256"
	// TimeFormatISO8601DateTime represents the Go time format for an ISO 8601 date time string.
	TimeFormatISO8601DateTime = "20060102T150405Z"
	// TimeFormatISO8601DateTime represents the Go time format for an ISO 8601 date string.
	TimeFormatISO8601Date = "20060102"
	// RequestTypeAWS4 represents the type of requests signed by the Signer.
	RequestTypeAWS4 = "aws4_request"
	// HashUnsignedPayload represents a predefined hash for an unsigned payload.
	HashUnsignedPayload = "UNSIGNED-PAYLOAD"
	// HashEmptyPayload represents the SHA256 hash of an empty payload (an empty string).
	HashEmptyPayload = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
)

Variables

This section is empty.

Functions

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats the given time using the ISO 8601 date format.

func FormatDateTime

func FormatDateTime(t time.Time) string

FormatDateTime formats the given time using the ISO 8601 date time format.

func GetHost

func GetHost(req *http.Request) string

GetHost returns the host for the request, preferring the req.Host value if set, falling back to the host of the URL if defined.

func GetURLPath

func GetURLPath(u *url.URL) string

GetURLPath returns the path for a given URL, preferring the url.Opaque value if defined, falling back to the value of url.EscapedPath().

If defined, url.Opaque must be in the form of:

"//<hostname>/<path>"

func HMACSHA256

func HMACSHA256(key []byte, data []byte) []byte

HMACSHA256 creates a HMAC-SHA256 signature of the given data using the provided key, ignoring any errors returned for caller's convenience and easier chaining.

func ParseDate

func ParseDate(s string) (time.Time, error)

ParseDate parses the provided string using the ISO 8601 date format.

func ParseDateTime

func ParseDateTime(s string) (time.Time, error)

ParseDateTime parses the provided string using the ISO 8601 date time format.

func SanitizeHost

func SanitizeHost(req *http.Request)

SanitizeHost sanitizes the host of the request, removing the port if it is the default one for the request's scheme.

func TrimAll

func TrimAll(s string) string

TrimAll strips all leading and trailing whitespaces and replaces multiple subsequent whitespaces in the string with single ones.

Types

This section is empty.

Jump to

Keyboard shortcuts

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