utils

package
v0.0.0-...-b702281 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// NetworkModeAWSVPC specifies the AWS VPC network mode.
	NetworkModeAWSVPC = "awsvpc"

	// RequestTypeCreds specifies the request type of CredentialsHandler.
	RequestTypeCreds = "credentials"

	// RequestTypeTaskMetadata specifies the task metadata request type of TaskContainerMetadataHandler.
	RequestTypeTaskMetadata = "task metadata"

	// RequestTypeContainerMetadata specifies the container metadata request type of TaskContainerMetadataHandler.
	RequestTypeContainerMetadata = "container metadata"

	// RequestTypeTaskStats specifies the task stats request type of StatsHandler.
	RequestTypeTaskStats = "task stats"

	// RequestTypeContainerStats specifies the container stats request type of StatsHandler.
	RequestTypeContainerStats = "container stats"

	// RequestTypeAgentMetadata specifies the Agent metadata request type of AgentMetadataHandler.
	RequestTypeAgentMetadata = "agent metadata"

	// RequestTypeContainerAssociations specifies the container associations request type of ContainerAssociationsHandler.
	RequestTypeContainerAssociations = "container associations"

	// RequestTypeContainerAssociation specifies the container association request type of ContainerAssociationHandler.
	RequestTypeContainerAssociation = "container association"

	// AnythingButSlashRegEx is a regex pattern that matches any string without slash.
	AnythingButSlashRegEx = "[^/]*"

	// AnythingRegEx is a regex pattern that matches anything.
	AnythingRegEx = ".*"

	// AnythingButEmptyRegEx is a regex pattern that matches anything but an empty string.
	AnythingButEmptyRegEx = ".+"
)

Variables

This section is empty.

Functions

func ConstructMuxVar

func ConstructMuxVar(name string, pattern string) string

ConstructMuxVar constructs the mux var that is used in the gorilla/mux styled path, example: {id}, {id:[0-9]+}.

func GetMuxValueFromRequest

func GetMuxValueFromRequest(r *http.Request, gorillaMuxName string) (string, bool)

GetMuxValueFromRequest extracts the mux value from the request using a gorilla mux name

func Is5XXStatus

func Is5XXStatus(statusCode int) bool

func LimitReachedHandler

func LimitReachedHandler(auditLogger audit.AuditLogger) func(http.ResponseWriter, *http.Request)

LimitReachedHandler logs the throttled request in the credentials audit log

func ValueFromRequest

func ValueFromRequest(r *http.Request, field string) (string, bool)

ValueFromRequest returns the value of a field in the http request. The boolean value is set to true if the field exists in the query.

func WriteJSONResponse

func WriteJSONResponse(
	w http.ResponseWriter,
	httpStatusCode int,
	response interface{},
	requestType string,
)

Marshals the provided response to JSON and writes it to the ResponseWriter with the provided status code and application/json Content-Type header. Writes an empty JSON '{}' response if JSON marshaling fails and logs the error.

func WriteJSONToResponse

func WriteJSONToResponse(w http.ResponseWriter, httpStatusCode int, responseJSON []byte, requestType string)

WriteJSONToResponse writes the header, JSON response to a ResponseWriter, and log the error if necessary.

func WriteResponseIfMarshalError

func WriteResponseIfMarshalError(w http.ResponseWriter, err error) error

WriteResponseIfMarshalError checks the 'err' response of the json.Marshal function. if this function returns an error, then it has already written a response to the http writer, and the calling function should return.

Types

type ErrorMessage

type ErrorMessage struct {
	Code          string `json:"code"`
	Message       string `json:"message"`
	HTTPErrorCode int
}

ErrorMessage is used to store the human-readable error Code and a descriptive Message that describes the error. This struct is marshalled and returned in the HTTP response.

Jump to

Keyboard shortcuts

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