request

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: BSD-2-Clause Imports: 18 Imported by: 23

Documentation

Index

Constants

View Source
const (
	ErrorCodeInternalServerError   = "internal-server-error"
	ErrorCodeUnexpectedResponse    = "unexpected-response"
	ErrorCodeTooManyRequests       = "too-many-requests"
	ErrorCodeBadRequest            = "bad-request"
	ErrorCodeUnauthenticated       = "unauthenticated"
	ErrorCodeUnauthorized          = "unauthorized"
	ErrorCodeResourceNotFound      = "resource-not-found"
	ErrorCodeResourceTooLarge      = "resource-too-large"
	ErrorCodeHeaderMissing         = "header-missing"
	ErrorCodeHeaderInvalid         = "header-invalid"
	ErrorCodeParameterMissing      = "parameter-missing"
	ErrorCodeParameterInvalid      = "parameter-invalid"
	ErrorCodeJSONNotFound          = "json-not-found"
	ErrorCodeJSONMalformed         = "json-malformed"
	ErrorCodeDigestsNotEqual       = "digests-not-equal"
	ErrorCodeMediaTypeNotSupported = "media-type-not-supported"
	ErrorCodeExtensionNotSupported = "extension-not-supported"
)
View Source
const (
	HTTPHeaderTraceRequest = "X-Tidepool-Trace-Request"
	HTTPHeaderTraceSession = "X-Tidepool-Trace-Session"
)

Variables

This section is empty.

Functions

func CopyTrace

func CopyTrace(ctx context.Context, req *http.Request) error

func DecodeObject

func DecodeObject(source structure.Source, reader io.Reader, object interface{}) error

func DecodeOptionalRequestPathParameter added in v1.31.0

func DecodeOptionalRequestPathParameter(req *rest.Request, key string, validator func(value string) bool) (*string, error)

func DecodeRequestBody

func DecodeRequestBody(req *http.Request, object interface{}) error

func DecodeRequestPathParameter added in v1.27.0

func DecodeRequestPathParameter(req *rest.Request, key string, validator func(value string) bool) (string, error)

func DecodeRequestQuery

func DecodeRequestQuery(req *http.Request, objectParsables ...structure.ObjectParsable) error

func DecodeResponseBody

func DecodeResponseBody(res *http.Response, object interface{}) error

func DecodeValues

func DecodeValues(values map[string][]string, objectParsables ...structure.ObjectParsable) error

func ErrorBadRequest

func ErrorBadRequest() error

func ErrorDigestsNotEqual added in v1.31.0

func ErrorDigestsNotEqual(value string, calculated string) error

func ErrorExtensionNotSupported added in v1.31.0

func ErrorExtensionNotSupported(value string) error

func ErrorHeaderInvalid added in v1.27.0

func ErrorHeaderInvalid(key string) error

func ErrorHeaderMissing added in v1.27.0

func ErrorHeaderMissing(key string) error

func ErrorInternalServerError added in v1.27.0

func ErrorInternalServerError(err error) error

func ErrorJSONMalformed

func ErrorJSONMalformed() error

func ErrorJSONNotFound added in v1.31.0

func ErrorJSONNotFound() error

func ErrorMediaTypeNotSupported added in v1.31.0

func ErrorMediaTypeNotSupported(value string) error

func ErrorParameterInvalid added in v1.27.0

func ErrorParameterInvalid(key string) error

func ErrorParameterMissing

func ErrorParameterMissing(key string) error

func ErrorResourceNotFound

func ErrorResourceNotFound() error

func ErrorResourceNotFoundWithID

func ErrorResourceNotFoundWithID(id string) error

func ErrorResourceNotFoundWithIDAndOptionalRevision added in v1.29.0

func ErrorResourceNotFoundWithIDAndOptionalRevision(id string, revision *int) error

func ErrorResourceNotFoundWithIDAndRevision added in v1.27.0

func ErrorResourceNotFoundWithIDAndRevision(id string, revision int) error

func ErrorResourceTooLarge added in v1.31.0

func ErrorResourceTooLarge() error

func ErrorTooManyRequests added in v1.24.0

func ErrorTooManyRequests() error

func ErrorUnauthenticated

func ErrorUnauthenticated() error

func ErrorUnauthorized

func ErrorUnauthorized() error

func ErrorUnexpectedResponse

func ErrorUnexpectedResponse(res *http.Response, req *http.Request) error

func GetErrorFromContext added in v1.28.0

func GetErrorFromContext(ctx context.Context) error

func IsErrorInternalServerError added in v1.27.0

func IsErrorInternalServerError(err error) bool

func IsErrorResourceNotFound added in v1.27.0

func IsErrorResourceNotFound(err error) bool

func IsErrorUnauthenticated added in v1.27.0

func IsErrorUnauthenticated(err error) bool

func IsErrorUnauthorized added in v1.27.0

func IsErrorUnauthorized(err error) bool

func IsStatusCodeClientError added in v1.27.0

func IsStatusCodeClientError(statusCode int) bool

func IsStatusCodeRedirection added in v1.27.0

func IsStatusCodeRedirection(statusCode int) bool

func IsStatusCodeSuccess added in v1.27.0

func IsStatusCodeSuccess(statusCode int) bool

func NewContextWithContextError added in v1.28.0

func NewContextWithContextError(ctx context.Context) context.Context

func NewContextWithDetails

func NewContextWithDetails(ctx context.Context, details Details) context.Context

func NewContextWithTraceRequest

func NewContextWithTraceRequest(ctx context.Context, traceRequest string) context.Context

func NewContextWithTraceSession

func NewContextWithTraceSession(ctx context.Context, traceSession string) context.Context

func NormalizeObjects

func NormalizeObjects(source structure.Source, objects ...interface{}) error

func ParseArrayParseableStreamObject

func ParseArrayParseableStreamObject(source structure.Source, reader io.Reader, arrayParsable structure.ArrayParsable) error

func ParseDigestMD5Header added in v1.27.0

func ParseDigestMD5Header(header http.Header, key string) (*string, error)

func ParseIntHeader added in v1.27.0

func ParseIntHeader(header http.Header, key string) (*int, error)

func ParseMediaTypeHeader added in v1.27.0

func ParseMediaTypeHeader(header http.Header, key string) (*string, error)

func ParseObjectParseableStreamObject

func ParseObjectParseableStreamObject(source structure.Source, reader io.Reader, objectParsable structure.ObjectParsable) error

func ParseSimpleStreamObject

func ParseSimpleStreamObject(reader io.Reader, object interface{}) error

func ParseSingletonHeader added in v1.31.0

func ParseSingletonHeader(header http.Header, key string) (*string, error)

func ParseStreamObject

func ParseStreamObject(source structure.Source, reader io.Reader, object interface{}) error

func ParseValuesObjects

func ParseValuesObjects(values map[string][]string, objectParsables ...structure.ObjectParsable) error

func SetErrorToContext added in v1.28.0

func SetErrorToContext(ctx context.Context, err error)

func StatusCodeForError

func StatusCodeForError(err error) int

func TraceRequestFromContext

func TraceRequestFromContext(ctx context.Context) string

func TraceSessionFromContext

func TraceSessionFromContext(ctx context.Context) string

func ValidateObjects

func ValidateObjects(source structure.Source, objects ...interface{}) error

Types

type ArrayParametersMutator added in v1.27.0

type ArrayParametersMutator struct {
	Parameters map[string][]string
}

func NewArrayParametersMutator added in v1.27.0

func NewArrayParametersMutator(parameters map[string][]string) *ArrayParametersMutator

func (*ArrayParametersMutator) MutateRequest added in v1.27.0

func (p *ArrayParametersMutator) MutateRequest(req *http.Request) error

type Condition added in v1.29.0

type Condition struct {
	Revision *int `json:"revision,omitempty"`
}

func NewCondition added in v1.29.0

func NewCondition() *Condition

func (*Condition) MutateRequest added in v1.29.0

func (c *Condition) MutateRequest(req *http.Request) error

func (*Condition) Parse added in v1.29.0

func (c *Condition) Parse(parser structure.ObjectParser)

func (*Condition) Validate added in v1.29.0

func (c *Condition) Validate(validator structure.Validator)

type ContextError added in v1.28.0

type ContextError struct {
	// contains filtered or unexported fields
}

func ContextErrorFromContext added in v1.28.0

func ContextErrorFromContext(ctx context.Context) *ContextError

func NewContextError added in v1.28.0

func NewContextError() *ContextError

func (*ContextError) Get added in v1.28.0

func (c *ContextError) Get() error

func (*ContextError) Set added in v1.28.0

func (c *ContextError) Set(err error)

type Details

type Details interface {
	Method() Method

	IsService() bool
	IsUser() bool
	UserID() string

	HasToken() bool
	Token() string
}

func DetailsFromContext

func DetailsFromContext(ctx context.Context) Details

func NewDetails

func NewDetails(method Method, userID string, token string) Details

type HeaderMutator added in v1.26.0

type HeaderMutator struct {
	Key   string
	Value string
}

func NewHeaderMutator added in v1.26.0

func NewHeaderMutator(key string, value string) *HeaderMutator

func (*HeaderMutator) MutateRequest added in v1.27.0

func (h *HeaderMutator) MutateRequest(req *http.Request) error

func (*HeaderMutator) MutateResponse added in v1.27.0

func (h *HeaderMutator) MutateResponse(res http.ResponseWriter) error

type HeadersInspector added in v1.27.0

type HeadersInspector struct {
	Headers http.Header
}

func NewHeadersInspector added in v1.27.0

func NewHeadersInspector() *HeadersInspector

func (*HeadersInspector) InspectResponse added in v1.27.0

func (h *HeadersInspector) InspectResponse(res *http.Response) error

type Method

type Method string
const (
	MethodServiceSecret   Method = "service secret"
	MethodAccessToken     Method = "access token"
	MethodSessionToken    Method = "session token"
	MethodRestrictedToken Method = "restricted token"
)

type ParameterMutator added in v1.26.0

type ParameterMutator struct {
	Key   string
	Value string
}

func NewParameterMutator added in v1.26.0

func NewParameterMutator(key string, value string) *ParameterMutator

func (*ParameterMutator) MutateRequest added in v1.27.0

func (p *ParameterMutator) MutateRequest(req *http.Request) error

type ParametersMutator added in v1.26.0

type ParametersMutator struct {
	Parameters map[string]string
}

func NewParametersMutator added in v1.26.0

func NewParametersMutator(parameters map[string]string) *ParametersMutator

func (*ParametersMutator) MutateRequest added in v1.27.0

func (p *ParametersMutator) MutateRequest(req *http.Request) error

type RequestMutator added in v1.27.0

type RequestMutator interface {
	MutateRequest(req *http.Request) error
}

type Responder

type Responder struct {
	// contains filtered or unexported fields
}

func MustNewResponder

func MustNewResponder(res rest.ResponseWriter, req *rest.Request) *Responder

func NewResponder

func NewResponder(res rest.ResponseWriter, req *rest.Request) (*Responder, error)

func (*Responder) Bytes added in v1.27.0

func (r *Responder) Bytes(statusCode int, bites []byte, mutators ...ResponseMutator)

func (*Responder) Data

func (r *Responder) Data(statusCode int, data interface{}, mutators ...ResponseMutator)

func (*Responder) Empty

func (r *Responder) Empty(statusCode int, mutators ...ResponseMutator)

func (*Responder) Error

func (r *Responder) Error(statusCode int, err error, mutators ...ResponseMutator)

func (*Responder) InternalServerError added in v1.27.0

func (r *Responder) InternalServerError(err error, mutators ...ResponseMutator)

func (*Responder) Reader added in v1.27.0

func (r *Responder) Reader(statusCode int, reader io.Reader, mutators ...ResponseMutator)

func (*Responder) Redirect

func (r *Responder) Redirect(statusCode int, url string, mutators ...ResponseMutator)

func (*Responder) RespondIfError added in v1.27.0

func (r *Responder) RespondIfError(err error, mutators ...ResponseMutator) bool

func (*Responder) SetCookie

func (r *Responder) SetCookie(cookie *http.Cookie)

func (*Responder) String added in v1.27.0

func (r *Responder) String(statusCode int, str string, mutators ...ResponseMutator)

type ResponseInspector added in v1.27.0

type ResponseInspector interface {
	InspectResponse(res *http.Response) error
}

type ResponseMutator added in v1.27.0

type ResponseMutator interface {
	MutateResponse(res http.ResponseWriter) error
}

type Sanitizable

type Sanitizable interface {
	Sanitize(details Details) error
}

type Values

type Values struct {
	// contains filtered or unexported fields
}

func NewValues

func NewValues(values *map[string][]string) *Values

func NewValuesParser

func NewValuesParser(base *structureBase.Base, values *map[string][]string) *Values

func (*Values) Array

func (v *Values) Array(reference string) *[]interface{}

func (*Values) Bool

func (v *Values) Bool(reference string) *bool

func (*Values) Error

func (v *Values) Error() error

func (*Values) Exists

func (v *Values) Exists() bool

func (*Values) Float64

func (v *Values) Float64(reference string) *float64

func (*Values) ForgivingTime added in v1.32.2

func (v *Values) ForgivingTime(reference string, layout string) *time.Time

ForgivingTime is a parser added specifically to handle https://tidepool.atlassian.net/browse/BACK-1161 It should be deprecated once Dexcom fixes their API.

func (*Values) HasError added in v1.24.0

func (v *Values) HasError() bool

func (*Values) HasMeta added in v1.24.0

func (v *Values) HasMeta() bool

func (*Values) HasSource added in v1.24.0

func (v *Values) HasSource() bool

func (*Values) Int

func (v *Values) Int(reference string) *int

func (*Values) Interface

func (v *Values) Interface(reference string) *interface{}

func (*Values) Meta added in v1.24.0

func (v *Values) Meta() interface{}

func (*Values) NotParsed

func (v *Values) NotParsed() error

func (*Values) Object

func (v *Values) Object(reference string) *map[string]interface{}

func (*Values) Origin added in v1.24.0

func (v *Values) Origin() structure.Origin

func (*Values) Parse

func (v *Values) Parse(objectParsable structure.ObjectParsable) error

func (*Values) ReferenceExists

func (v *Values) ReferenceExists(reference string) bool

func (*Values) References

func (v *Values) References() []string

func (*Values) ReportError added in v1.24.0

func (v *Values) ReportError(err error)

func (*Values) Source added in v1.24.0

func (v *Values) Source() structure.Source

func (*Values) String

func (v *Values) String(reference string) *string

func (*Values) StringArray

func (v *Values) StringArray(reference string) *[]string

func (*Values) Time

func (v *Values) Time(reference string, layout string) *time.Time

func (*Values) WithMeta

func (v *Values) WithMeta(meta interface{}) structure.ObjectParser

func (*Values) WithOrigin added in v1.24.0

func (v *Values) WithOrigin(origin structure.Origin) structure.ObjectParser

func (*Values) WithReferenceArrayParser

func (v *Values) WithReferenceArrayParser(reference string) structure.ArrayParser

func (*Values) WithReferenceErrorReporter added in v1.31.0

func (v *Values) WithReferenceErrorReporter(reference string) structure.ErrorReporter

func (*Values) WithReferenceObjectParser

func (v *Values) WithReferenceObjectParser(reference string) structure.ObjectParser

func (*Values) WithSource

func (v *Values) WithSource(source structure.Source) structure.ObjectParser

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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