http

package
v0.0.0-...-8f66fda Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultContentType               = "application/json"
	DefaultPathBindingPrefix         = "path."
	DefaultHeaderBindingPrefix       = "header."
	DefaultQueryParamBindingPrefix   = "query."
	DefaultPayloadBindingPrefix      = ""
	DefaultSkipFieldDirective        = "-"
	DefaultBindToFieldNameDirective  = "+"
	DefaultBodyBindingDirective      = "body"
	DefaultEmptyDirectiveHandling    = SkipField
	DefaultOmitEmptyDirective        = "omitempty"
	DefaultIncludeEmptyDirective     = "includeempty"
	DefaultEmptyValueHandlingDefault = OmitEmpty

	ContentTypeHeader = "Content-Type"
	AcceptsHeader     = "Accepts"

	AcceptLanguageKey = "$_accept_language"
)
View Source
const (
	PutCollection     = Put + collection
	PostCollection    = Post + collection
	GetCollection     = Get + collection
	PatchCollection   = Patch + collection
	DeleteCollection  = Delete_ + collection
	HeadCollection    = Head + collection
	OptionsCollection = Options + collection

	PutInstance     = Put + instance
	PostInstance    = Post + instance
	GetInstance     = Get + instance
	PatchInstance   = Patch + instance
	DeleteInstance  = Delete_ + instance
	HeadInstance    = Head + instance
	OptionsInstance = Options + instance
)
View Source
const InvalidHttpOp = 0b00000000
View Source
const StatusLimitExceeded = 402

Variables

View Source
var (
	DefaultBindFromRequestTool *structs.Tool
)
View Source
var (
	DefaultBindToResponseTool *structs.Tool
)

Functions

func BindFromRequest

func BindFromRequest(request *http.Request, resourceType reflect.Type, subject auth.Subject, scope string) (resource.Resource, gomerr.Gomerr)

func BindToResponse

func BindToResponse(result reflect.Value, header http.Header, scope string, acceptLanguage string) (output []byte, ge gomerr.Gomerr)

BindToResponse TODO: add support for data format type

func SetBindFromRequestConfiguration

func SetBindFromRequestConfiguration(requestConfiguration BindFromRequestConfiguration) *structs.Tool

func SetBindToResponseConfiguration

func SetBindToResponseConfiguration(responseConfiguration BindToResponseConfiguration) *structs.Tool

Types

type BindDirectiveConfiguration

type BindDirectiveConfiguration struct {
	// Default prefixes for qualified directives
	PathBindingPrefix       string
	HeaderBindingPrefix     string
	QueryParamBindingPrefix string
	PayloadBindingPrefix    string

	// Default values for unqualified directives
	SkipField    string
	IncludeField string
	BindBody     string

	// Defines how a field's binding be handled if no directive is specified. Default is to skip.
	EmptyDirectiveHandling EmptyDirectiveHandlingType

	OmitEmptyDirective    string
	IncludeEmptyDirective string

	// Defines how an empty value is marshaled unless overridden by OmitEmptyDirective or IncludeEmptyDirective. Default
	// is to omit.
	EmptyValueHandlingDefault EmptyValueHandlingType
}

func NewBindDirectiveConfiguration

func NewBindDirectiveConfiguration() BindDirectiveConfiguration

type BindFromRequestConfiguration

type BindFromRequestConfiguration struct {
	BindConfiguration bind2.Configuration
	BindDirectiveConfiguration
	// contains filtered or unexported fields
}

BindFromRequestConfiguration TODO: add config option mechanism...

func NewBindFromRequestConfiguration

func NewBindFromRequestConfiguration() BindFromRequestConfiguration

type BindToResponseConfiguration

type BindToResponseConfiguration struct {
	BindConfiguration bind.Configuration
	BindDirectiveConfiguration
	// contains filtered or unexported fields
}

BindToResponseConfiguration TODO: add config option mechanism...

func NewBindToResponseConfiguration

func NewBindToResponseConfiguration() BindToResponseConfiguration

type EmptyDirectiveHandlingType

type EmptyDirectiveHandlingType int
const (
	SkipField EmptyDirectiveHandlingType = iota
	BindToFieldName
)

type EmptyValueHandlingType

type EmptyValueHandlingType int
const (
	OmitEmpty EmptyValueHandlingType = iota
	IncludeEmpty
)

type Marshal

type Marshal func(toMarshal interface{}) ([]byte, error)

Marshal provides a function to convert the toMarshal to bytes suitable for returning in a response body.

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
}

type Method

type Method = Op
const (
	Put     Method // 0b00000001
	Post           // 0b00000010
	Get            // 0b00000011
	Patch          // 0b00000100
	Delete_        // 0b00000101
	Head           // 0b00000110
	Options        // 0b00000111

)

type Op

type Op byte

Op has 8 bits where the bottom five bits correspond to the action type, the sixth and seventh bit specifies what resource type the action is against (instance or a collection; a singleton counts as an instance) and the highest bit indicates if the op is built-in or customer-defined. The seventh bit is reserved. Use NewOp rather than try to construct manually to allow for the introduction of new, built-in Method values.

func NewOp

func NewOp(method Method, category resource.Category) Op

func (Op) IsBuiltIn

func (o Op) IsBuiltIn() bool

func (Op) IsValid

func (o Op) IsValid() bool

func (Op) Method

func (o Op) Method() string

func (Op) ResourceType

func (o Op) ResourceType() resource.Category

type StatusCoder

type StatusCoder interface {
	StatusCode() int
}

type Unmarshal

type Unmarshal func(toUnmarshal []byte, ptrToTarget interface{}) error

Unmarshal defines a function that processes the input and stores the result in the value pointed to by ptrToTarget. If ptrToTarget is nil, not a pointer, or otherwise unprocessable, Unmarshal returns a gomerr.Gomerr.

Jump to

Keyboard shortcuts

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