util

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2018 License: Apache-2.0, BSD-3-Clause, MIT Imports: 14 Imported by: 22

Documentation

Overview

Package util contains web utils for APIs, clients and error handling

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFoundInStorage error returned from storage when entity is not found
	ErrNotFoundInStorage = errors.New("not found")

	// ErrAlreadyExistsInStorage error returned from storage when entity has conflicting fields
	ErrAlreadyExistsInStorage = errors.New("unique constraint violation")
)

Functions

func BodyToBytes

func BodyToBytes(closer io.ReadCloser) ([]byte, error)

BodyToBytes of the request inside given struct

func BodyToObject

func BodyToObject(closer io.ReadCloser, object interface{}) error

BodyToObject of the request inside given struct

func BytesToObject

func BytesToObject(bytes []byte, object interface{}) error

BytesToObject converts the provided bytes to object and validates it

func HandleInterrupts

func HandleInterrupts(ctx context.Context, cancel context.CancelFunc)

HandleInterrupts handles process signal interrupts

func HandleResponseError

func HandleResponseError(response *http.Response) error

HandleResponseError builds at HttpErrorResponse from the given response.

func HandleStorageError

func HandleStorageError(err error, entityName, entityID string) error

HandleStorageError handles storage errors by converting them to relevant HTTPErrors

func HasRFC3986ReservedSymbols

func HasRFC3986ReservedSymbols(input string) bool

HasRFC3986ReservedSymbols returns true if input contains any reserver characters as defined in RFC3986 section oidc_authn.oidc_authn

func NewJSONResponse

func NewJSONResponse(code int, value interface{}) (*web.Response, error)

NewJSONResponse turns plain object into a byte array representing JSON value and wraps it in web.Response

func RequestBodyToBytes

func RequestBodyToBytes(request *http.Request) ([]byte, error)

RequestBodyToBytes reads the request body and returns []byte with its content or an error if the media type is incorrect or if the body is not a valid JSON

func SendRequest

func SendRequest(ctx context.Context, doRequest DoRequestFunc, method, url string, params map[string]string, body interface{}) (*http.Response, error)

SendRequest sends a request to the specified client and the provided URL with the specified parameters and body.

func ToRFCFormat

func ToRFCFormat(timestamp time.Time) string

ToRFCFormat converts a time.Time timestamp to RFC3339 format

func WriteError

func WriteError(err error, writer http.ResponseWriter)

WriteError sends a JSON containing the error to the response writer

func WriteJSON

func WriteJSON(writer http.ResponseWriter, code int, value interface{}) error

WriteJSON writes a JSON value and sets the specified HTTP Status code

Types

type DoRequestFunc

type DoRequestFunc func(request *http.Request) (*http.Response, error)

DoRequestFunc is an alias for any function that takes an http request and returns a response and error

type EmptyResponseBody added in v0.1.2

type EmptyResponseBody struct{}

EmptyResponseBody represents an empty response body value

type ErrBadRequestStorage added in v0.1.6

type ErrBadRequestStorage error

type HTTPError

type HTTPError struct {
	ErrorType   string `json:"error,omitempty"`
	Description string `json:"description,omitempty"`
	StatusCode  int    `json:"-"`
}

HTTPError is an error type that provides error details compliant with the Open Service Broker API conventions

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error HTTPError should implement error

type InputValidator

type InputValidator interface {
	Validate() error
}

InputValidator should be implemented by types that need input validation check. For a reference refer to pkg/types

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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