body

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIMEJSON              = "application/json"
	MIMEXML               = "application/xml"
	MIMETEXTXML           = "text/xml"
	MIMEHTML              = "text/html"
	MIMETEXT              = "text/plain"
	MIMEPOSTFORM          = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTFORM = "multipart/form-data"
)

Content-Type MIME of the data formats.

View Source
const HeaderContentType = "Content-Type"

HeaderContentType content-type header key

Variables

This section is empty.

Functions

func NewErr

func NewErr(e error) *errBody

Types

type Body

type Body interface {
	// Body 构造http请求body
	Body() (io.Reader, error)
	// ContentType 返回 body 体结构相应的 Header content-type 类型
	ContentType() string
}

Body 构造请求的body

type File

type File struct {
	Field       string // 表单字段
	Filename    string // 文件名称
	ContentType string // 文件 content-type;若不指定,则根据 Content 判断
	Content     []byte // 文件内容
}

File 文件

type Form

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

Form 用于构建一个 x-www-form-urlencoded 消息格式的 body 体

func NewForm

func NewForm(u url.Values) *Form

NewForm return new Form

func NewFormFromMap

func NewFormFromMap(m map[string]interface{}) *Form

NewFormFromMap return new Form from map

func (*Form) Add

func (f *Form) Add(key string, value interface{}) *Form

func (*Form) Body

func (f *Form) Body() (io.Reader, error)

Body 构建 x-www-form-urlencoded 消息格式的消息体

func (*Form) ContentType

func (f *Form) ContentType() string

ContentType 构建 x-www-form-urlencoded 消息类型对应的content-type头信息

func (*Form) Del

func (f *Form) Del(key string) *Form

Del delete key from form

func (*Form) Encode

func (f *Form) Encode() string

Encode return url.Values.Encode()

func (*Form) Set

func (f *Form) Set(key string, value interface{}) *Form

type JSON

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

Json json body

func NewJSON

func NewJSON(v interface{}) *JSON

NewJSON return JSON

func (*JSON) Body

func (j *JSON) Body() (io.Reader, error)

Body return http req body

func (*JSON) Bytes

func (j *JSON) Bytes() ([]byte, error)

func (*JSON) ContentType

func (j *JSON) ContentType() string

ContentType return json content-type

type MultipartForm

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

MultipartForm multipart/form-data

func NewMultipartForm

func NewMultipartForm(uv url.Values, fs ...File) *MultipartForm

NewMultipartForm return new MultipartForm from url.Values

func NewMultipartFormFromMap

func NewMultipartFormFromMap(m map[string]interface{}, fs ...File) *MultipartForm

NewMultipartFormFromMap return new MultipartForm from map

func (*MultipartForm) Body

func (mf *MultipartForm) Body() (io.Reader, error)

Body 构建 multipart/form-data 格式的消息体

func (*MultipartForm) ContentType

func (mf *MultipartForm) ContentType() string

ContentType 构建 multipart/form-data 格式的 header 头

func (*MultipartForm) CreateFormFile

func (mf *MultipartForm) CreateFormFile(w *multipart.Writer, fieldName, filename string, contentType string, fileContent []byte) (int, error)

CreateFormFile Create form file

type XML

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

XML xml body

func NewXML

func NewXML(v interface{}) *XML

NewXML return *XML

func (*XML) Body

func (x *XML) Body() (io.Reader, error)

Body return http req body

func (*XML) Bytes

func (x *XML) Bytes() ([]byte, error)

func (*XML) ContentType

func (x *XML) ContentType() string

ContentType return xml content-type

Jump to

Keyboard shortcuts

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