httpbody

package
v0.5.22 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 16 Imported by: 0

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

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

func NewHTTPBody(body io.Reader, headers http.Header) *HTTPBody

NewHTTPBody creates a new HTTPBody from the specified reader and headers.

func (*HTTPBody) Bool

func (body *HTTPBody) Bool() (bool, error)

Bool returns the body as an bool.

func (*HTTPBody) Bytes

func (body *HTTPBody) Bytes() ([]byte, error)

Bytes returns the body as a byte slice.

func (*HTTPBody) ConvertRecipes

func (body *HTTPBody) ConvertRecipes() []convert.Recipe

ConvertRecipes contains recipes for go-convert.

func (*HTTPBody) Float32

func (body *HTTPBody) Float32() (float32, error)

Float32 returns the body as an float32.

func (*HTTPBody) Float64

func (body *HTTPBody) Float64() (float64, error)

Float64 returns the body as an float64.

func (*HTTPBody) FormValues

func (body *HTTPBody) FormValues() (*URLValues, error)

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) Int

func (body *HTTPBody) Int() (int, error)

Int returns the body as an int.

func (*HTTPBody) Int16

func (body *HTTPBody) Int16() (int16, error)

Int16 returns the body as an int16.

func (*HTTPBody) Int32

func (body *HTTPBody) Int32() (int32, error)

Int32 returns the body as an int64.

func (*HTTPBody) Int64

func (body *HTTPBody) Int64() (int64, error)

Int64 returns the body as an int64.

func (*HTTPBody) Int8

func (body *HTTPBody) Int8() (int8, error)

Int8 returns the body as an int8.

func (*HTTPBody) JSON

func (body *HTTPBody) JSON() *HTTPBodyJSON

JSON treats the body as JSON encoded data.

func (*HTTPBody) Length

func (body *HTTPBody) Length() (int64, error)

Length returns the body's length.

func (*HTTPBody) MustBool

func (body *HTTPBody) MustBool() bool

MustBool returns the body as an bool, it panics on failure.

func (*HTTPBody) MustBytes

func (body *HTTPBody) MustBytes() []byte

MustBytes returns the body as a byte slice, it panics on failure.

func (*HTTPBody) MustFloat32

func (body *HTTPBody) MustFloat32() float32

MustFloat32 returns the body as an float32, it panics on failure.

func (*HTTPBody) MustFloat64

func (body *HTTPBody) MustFloat64() float64

MustFloat64 returns the body as an float64, it panics on failure.

func (*HTTPBody) MustFormValues

func (body *HTTPBody) MustFormValues() *URLValues

MustFormValues returns the body as url.FormValues.

func (*HTTPBody) MustInt

func (body *HTTPBody) MustInt() int

MustInt returns the body as an int, it panics on failure.

func (*HTTPBody) MustInt16

func (body *HTTPBody) MustInt16() int16

MustInt16 returns the body as an int16, it panics on failure.

func (*HTTPBody) MustInt32

func (body *HTTPBody) MustInt32() int32

MustInt32 returns the body as an int64, it panics on failure.

func (*HTTPBody) MustInt64

func (body *HTTPBody) MustInt64() int64

MustInt64 returns the body as an int64, it panics on failure.

func (*HTTPBody) MustInt8

func (body *HTTPBody) MustInt8() int8

MustInt8 returns the body as an int8, it panics on failure.

func (*HTTPBody) MustLength

func (body *HTTPBody) MustLength() int64

MustLength returns the body's length, it panics on failure.

func (*HTTPBody) MustString

func (body *HTTPBody) MustString() string

MustString returns the body as a string, it panics on failure.

func (*HTTPBody) MustUint

func (body *HTTPBody) MustUint() uint

MustUint returns the body as an uint, it panics on failure.

func (*HTTPBody) MustUint16

func (body *HTTPBody) MustUint16() uint16

MustUint16 returns the body as an uint16, it panics on failure.

func (*HTTPBody) MustUint32

func (body *HTTPBody) MustUint32() uint32

MustUint32 returns the body as an uint32, it panics on failure.

func (*HTTPBody) MustUint64

func (body *HTTPBody) MustUint64() uint64

MustUint64 returns the body as an uint64, it panics on failure.

func (*HTTPBody) MustUint8

func (body *HTTPBody) MustUint8() uint8

MustUint8 returns the body as an uint8, it panics on failure.

func (*HTTPBody) Reader

func (body *HTTPBody) Reader() io.ReadCloser

Reader returns the body as an reader.

func (*HTTPBody) SetBool

func (body *HTTPBody) SetBool(b bool)

SetBool sets the body to the specified bool.

func (*HTTPBody) SetBytes

func (body *HTTPBody) SetBytes(b []byte)

SetBytes sets the body to the specified byte slice.

func (*HTTPBody) SetFloat32

func (body *HTTPBody) SetFloat32(f float32)

SetFloat32 sets the body to the specified float32.

func (*HTTPBody) SetFloat64

func (body *HTTPBody) SetFloat64(f float64)

SetFloat64 sets the body to the specified float64.

func (*HTTPBody) SetFormValues

func (body *HTTPBody) SetFormValues(v url.Values)

SetFormValues sets the body to the specified form values.

func (*HTTPBody) SetInt

func (body *HTTPBody) SetInt(i int)

SetInt sets the body to the specified int.

func (*HTTPBody) SetInt16

func (body *HTTPBody) SetInt16(i int16)

SetInt16 sets the body to the specified int16.

func (*HTTPBody) SetInt32

func (body *HTTPBody) SetInt32(i int32)

SetInt32 sets the body to the specified int64.

func (*HTTPBody) SetInt64

func (body *HTTPBody) SetInt64(i int64)

SetInt64 sets the body to the specified int64.

func (*HTTPBody) SetInt8

func (body *HTTPBody) SetInt8(i int8)

SetInt8 sets the body to the specified int8.

func (*HTTPBody) SetReader

func (body *HTTPBody) SetReader(r io.Reader)

SetReader sets the body to the contents of the specified reader.

func (*HTTPBody) SetString

func (body *HTTPBody) SetString(s string)

SetString sets the body to the specified string.

func (*HTTPBody) SetStringf

func (body *HTTPBody) SetStringf(format string, a ...interface{})

SetStringf sets the body to the specified string format.

func (*HTTPBody) SetUint

func (body *HTTPBody) SetUint(i uint)

SetUint sets the body to the specified int.

func (*HTTPBody) SetUint16

func (body *HTTPBody) SetUint16(i uint16)

SetUint16 sets the body to the specified uint16.

func (*HTTPBody) SetUint32

func (body *HTTPBody) SetUint32(i uint32)

SetUint32 sets the body to the specified uint64.

func (*HTTPBody) SetUint64

func (body *HTTPBody) SetUint64(i uint64)

SetUint64 sets the body to the specified uint64.

func (*HTTPBody) SetUint8

func (body *HTTPBody) SetUint8(i uint8)

SetUint8 sets the body to the specified uint8.

func (*HTTPBody) String

func (body *HTTPBody) String() (string, error)

String returns the body as a string.

func (*HTTPBody) Uint

func (body *HTTPBody) Uint() (uint, error)

Uint returns the body as an uint.

func (*HTTPBody) Uint16

func (body *HTTPBody) Uint16() (uint16, error)

Uint16 returns the body as an uint16.

func (*HTTPBody) Uint32

func (body *HTTPBody) Uint32() (uint32, error)

Uint32 returns the body as an uint32.

func (*HTTPBody) Uint64

func (body *HTTPBody) Uint64() (uint64, error)

Uint64 returns the body as an uint64.

func (*HTTPBody) Uint8

func (body *HTTPBody) Uint8() (uint8, error)

Uint8 returns the body as an uint8.

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

func ParseURLValues(body *HTTPBody) (*URLValues, error)

ParseURLValues takes a HTTPBody and parses the url.Values, it returns a pointer to URLValues.

func (*URLValues) Add

func (v *URLValues) Add(key, value string)

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) Del

func (v *URLValues) Del(key string)

Del deletes the values associated with key.

func (*URLValues) Get

func (v *URLValues) Get(key string) string

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.

func (*URLValues) Set

func (v *URLValues) Set(key, value string)

Set sets the key to value. It replaces any existing values.

func (*URLValues) Values

func (v *URLValues) Values(key string) []string

Values returns all the values associated with the given key.

Jump to

Keyboard shortcuts

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