Documentation ¶
Overview ¶
Package util contains web utils for APIs, clients and error handling
Index ¶
- Variables
- func BodyToBytes(closer io.ReadCloser) ([]byte, error)
- func BodyToObject(closer io.ReadCloser, object interface{}) error
- func BytesToObject(bytes []byte, object interface{}) error
- func HandleInterrupts(ctx context.Context, cancel context.CancelFunc)
- func HandleResponseError(response *http.Response) error
- func HandleStorageError(err error, entityName string) error
- func HasRFC3986ReservedSymbols(input string) bool
- func NewJSONResponse(code int, value interface{}) (*web.Response, error)
- func RequestBodyToBytes(request *http.Request) ([]byte, error)
- func SendRequest(ctx context.Context, doRequest DoRequestFunc, method, url string, ...) (*http.Response, error)
- func SendRequestWithHeaders(ctx context.Context, doRequest DoRequestFunc, method, url string, ...) (*http.Response, error)
- func ToRFCFormat(timestamp time.Time) string
- func WriteError(err error, writer http.ResponseWriter)
- func WriteJSON(writer http.ResponseWriter, code int, value interface{}) error
- type DoRequestFunc
- type EmptyResponseBody
- type ErrBadRequestStorage
- type HTTPError
- type InputValidator
- type UnsupportedQueryError
Constants ¶
This section is empty.
Variables ¶
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") // ErrConcurrentResourceModification error returned when concurrent resource updates are happening ErrConcurrentResourceModification = errors.New("another resource update happened concurrently. Please reattempt the update") )
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 ¶
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 ¶
HandleResponseError builds at HttpErrorResponse from the given response.
func HandleStorageError ¶
HandleStorageError handles storage errors by converting them to relevant HTTPErrors
func HasRFC3986ReservedSymbols ¶
HasRFC3986ReservedSymbols returns true if input contains any reserver characters as defined in RFC3986 section oidc_authn.oidc_authn
func NewJSONResponse ¶
NewJSONResponse turns plain object into a byte array representing JSON value and wraps it in web.Response
func RequestBodyToBytes ¶
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 SendRequestWithHeaders ¶ added in v0.1.11
func SendRequestWithHeaders(ctx context.Context, doRequest DoRequestFunc, method, url string, params map[string]string, body interface{}, headers map[string]string) (*http.Response, error)
SendRequestWithHeaders sends a request to the specified client and the provided URL with the specified parameters, body and headers.
func ToRFCFormat ¶
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
Types ¶
type DoRequestFunc ¶
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 struct {
Cause error
}
ErrBadRequestStorage represents a storage error that should be translated to http.StatusBadRequest
func (*ErrBadRequestStorage) Error ¶ added in v0.3.0
func (e *ErrBadRequestStorage) Error() string
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 that Service Manager error handlers would propagate to the client
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
type UnsupportedQueryError ¶ added in v0.1.9
type UnsupportedQueryError struct {
Message string
}
UnsupportedQueryError is an error to show that the provided query cannot be executed
func (*UnsupportedQueryError) Error ¶ added in v0.1.9
func (uq *UnsupportedQueryError) Error() string