Documentation ¶
Overview ¶
Package httpbody contains a http body representation with a reusable body that can be consumed multiple times. It also provides setters and getters for special body formats such as JSON or XML.
Index ¶
- type HTTPBody
- func (body *HTTPBody) Bool() (bool, error)
- func (body *HTTPBody) Bytes() ([]byte, error)
- func (body *HTTPBody) ConvertRecipes() []convert.Recipe
- func (body *HTTPBody) Float32() (float32, error)
- func (body *HTTPBody) Float64() (float64, error)
- func (body *HTTPBody) FormValues() (*URLValues, error)
- func (body *HTTPBody) GetBestFittingObject() interface{}
- func (body *HTTPBody) Int() (int, error)
- func (body *HTTPBody) Int16() (int16, error)
- func (body *HTTPBody) Int32() (int32, error)
- func (body *HTTPBody) Int64() (int64, error)
- func (body *HTTPBody) Int8() (int8, error)
- func (body *HTTPBody) JSON() *HTTPBodyJSON
- func (body *HTTPBody) Length() (int64, error)
- func (body *HTTPBody) MustBool() bool
- func (body *HTTPBody) MustBytes() []byte
- func (body *HTTPBody) MustFloat32() float32
- func (body *HTTPBody) MustFloat64() float64
- func (body *HTTPBody) MustFormValues() *URLValues
- func (body *HTTPBody) MustInt() int
- func (body *HTTPBody) MustInt16() int16
- func (body *HTTPBody) MustInt32() int32
- func (body *HTTPBody) MustInt64() int64
- func (body *HTTPBody) MustInt8() int8
- func (body *HTTPBody) MustLength() int64
- func (body *HTTPBody) MustString() string
- func (body *HTTPBody) MustUint() uint
- func (body *HTTPBody) MustUint16() uint16
- func (body *HTTPBody) MustUint32() uint32
- func (body *HTTPBody) MustUint64() uint64
- func (body *HTTPBody) MustUint8() uint8
- func (body *HTTPBody) Reader() io.ReadCloser
- func (body *HTTPBody) SetBool(b bool)
- func (body *HTTPBody) SetBytes(b []byte)
- func (body *HTTPBody) SetFloat32(f float32)
- func (body *HTTPBody) SetFloat64(f float64)
- func (body *HTTPBody) SetFormValues(v url.Values)
- func (body *HTTPBody) SetInt(i int)
- func (body *HTTPBody) SetInt16(i int16)
- func (body *HTTPBody) SetInt32(i int32)
- func (body *HTTPBody) SetInt64(i int64)
- func (body *HTTPBody) SetInt8(i int8)
- func (body *HTTPBody) SetReader(r io.Reader)
- func (body *HTTPBody) SetString(s string)
- func (body *HTTPBody) SetStringf(format string, a ...interface{})
- func (body *HTTPBody) SetUint(i uint)
- func (body *HTTPBody) SetUint16(i uint16)
- func (body *HTTPBody) SetUint32(i uint32)
- func (body *HTTPBody) SetUint64(i uint64)
- func (body *HTTPBody) SetUint8(i uint8)
- func (body *HTTPBody) String() (string, error)
- func (body *HTTPBody) Uint() (uint, error)
- func (body *HTTPBody) Uint16() (uint16, error)
- func (body *HTTPBody) Uint32() (uint32, error)
- func (body *HTTPBody) Uint64() (uint64, error)
- func (body *HTTPBody) Uint8() (uint8, error)
- func (body *HTTPBody) XML() *HTTPBodyXML
- type HTTPBodyJSON
- func (jsn *HTTPBodyJSON) Decode(container interface{}) error
- func (jsn *HTTPBodyJSON) JQ(container interface{}, expression ...string) error
- func (jsn *HTTPBodyJSON) MustDecode(container interface{})
- func (jsn *HTTPBodyJSON) MustJQ(container interface{}, expression ...string)
- func (jsn *HTTPBodyJSON) Set(data interface{}) error
- type HTTPBodyXML
- type URLValues
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPBody ¶
type HTTPBody struct {
// contains filtered or unexported fields
}
HTTPBody provides setters and getters for the http body.
func NewHTTPBody ¶
NewHTTPBody creates a new HTTPBody from the specified reader and headers.
func (*HTTPBody) ConvertRecipes ¶
func (body *HTTPBody) ConvertRecipes() []convert.Recipe
ConvertRecipes contains recipes for go-convert.
func (*HTTPBody) FormValues ¶
FormValues returns the body as url.Values.
func (*HTTPBody) GetBestFittingObject ¶
func (body *HTTPBody) GetBestFittingObject() interface{}
GetBestFittingObject tries its best to return an appropriate object for the body.
func (*HTTPBody) JSON ¶
func (body *HTTPBody) JSON() *HTTPBodyJSON
JSON treats the body as JSON encoded data.
func (*HTTPBody) MustFloat32 ¶
MustFloat32 returns the body as an float32, it panics on failure.
func (*HTTPBody) MustFloat64 ¶
MustFloat64 returns the body as an float64, it panics on failure.
func (*HTTPBody) MustFormValues ¶
MustFormValues returns the body as url.FormValues.
func (*HTTPBody) MustLength ¶
MustLength returns the body's length, it panics on failure.
func (*HTTPBody) MustString ¶
MustString returns the body as a string, it panics on failure.
func (*HTTPBody) MustUint16 ¶
MustUint16 returns the body as an uint16, it panics on failure.
func (*HTTPBody) MustUint32 ¶
MustUint32 returns the body as an uint32, it panics on failure.
func (*HTTPBody) MustUint64 ¶
MustUint64 returns the body as an uint64, it panics on failure.
func (*HTTPBody) Reader ¶
func (body *HTTPBody) Reader() io.ReadCloser
Reader returns the body as an reader.
func (*HTTPBody) SetFloat32 ¶
SetFloat32 sets the body to the specified float32.
func (*HTTPBody) SetFloat64 ¶
SetFloat64 sets the body to the specified float64.
func (*HTTPBody) SetFormValues ¶
SetFormValues sets the body to the specified form values.
func (*HTTPBody) SetStringf ¶
SetStringf sets the body to the specified string format.
func (*HTTPBody) XML ¶
func (body *HTTPBody) XML() *HTTPBodyXML
XML treats the body as XML encoded data.
type HTTPBodyJSON ¶
type HTTPBodyJSON struct {
// contains filtered or unexported fields
}
HTTPBodyJSON provides JSON functions for the HTTPBody.
func (*HTTPBodyJSON) Decode ¶
func (jsn *HTTPBodyJSON) Decode(container interface{}) error
Decode decodes the body as JSON.
func (*HTTPBodyJSON) JQ ¶
func (jsn *HTTPBodyJSON) JQ(container interface{}, expression ...string) error
JQ runs an jq expression on the JSON body the result will be stored into container.
func (*HTTPBodyJSON) MustDecode ¶
func (jsn *HTTPBodyJSON) MustDecode(container interface{})
MustDecode decodes the body as JSON, evaluates the expression and puts the result into the container it will panic if something goes wrong.
func (*HTTPBodyJSON) MustJQ ¶
func (jsn *HTTPBodyJSON) MustJQ(container interface{}, expression ...string)
MustJQ runs an jq expression on the JSON body the result will be stored into container, if an error occurs it will panic.
func (*HTTPBodyJSON) Set ¶
func (jsn *HTTPBodyJSON) Set(data interface{}) error
Set sets the body to the specified json data.
type HTTPBodyXML ¶
type HTTPBodyXML struct {
// contains filtered or unexported fields
}
HTTPBodyXML provides XML functions for the HTTPBody.
func (*HTTPBodyXML) Set ¶
func (jsn *HTTPBodyXML) Set(data interface{}) error
Set sets the body to the specified json data.
type URLValues ¶
type URLValues struct {
// contains filtered or unexported fields
}
URLValues is a wrapper for url.Values but it works with HTTPBody.
func ParseURLValues ¶
ParseURLValues takes a HTTPBody and parses the url.Values, it returns a pointer to URLValues.
func (*URLValues) Add ¶
Add adds the value to key. It appends to any existing values associated with key.
func (*URLValues) ConvertRecipes ¶
func (v *URLValues) ConvertRecipes() []convert.Recipe
ConvertRecipes contains recipes for go-convert.
func (*URLValues) Get ¶
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns the empty string. To access multiple values, use the map directly.