request

package
v0.0.0-...-a4de9da Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRequest

func DefaultRequest(req *Request)

func SortParams

func SortParams(params ReqParams) string

So far only string data has been parsed The following analysis is based on actual needs !!! Null data is filtered

Types

type Payload

type Payload struct {
	Body        *bytes.Buffer
	ContentType string
}

func CreateFileData

func CreateFileData(Field, Filepath string, params ReqParams) (payload *Payload, err error)

type ReqParams

type ReqParams map[string]interface{}

func Struct2Params

func Struct2Params(params interface{}) (Params ReqParams, err error)

Transform any structure into a standard transmission data format Currently, null data filtering is not supported

type Request

type Request struct {
	Path         string
	Params       ReqParams
	Method       RequestMethod
	Header       map[string]string
	ContentType  RequestContentType
	Payload      *Payload
	RawQuery     string
	BasicAuthKey string
}

func NewRequest

func NewRequest(Path string, Options ...RequestOptions) *Request

func (*Request) BasicAuth

func (R *Request) BasicAuth(BasicAuth string) *Request

func (*Request) File

func (R *Request) File(Payload *Payload) *Request

func (*Request) Post

func (R *Request) Post(Params ReqParams) *Request

Simplifying external writing of excessive code adds syntactic sugar

func (*Request) Resources

func (R *Request) Resources() (Body io.ReadCloser, err error)

func (*Request) Send

func (R *Request) Send() (result []byte, err error)

type RequestContentType

type RequestContentType string
const (
	Json        RequestContentType = "application/json"
	FormUrl     RequestContentType = "application/x-www-form-urlencoded"
	MulFormData RequestContentType = "multipart/form-data"
)

type RequestMethod

type RequestMethod string
const (
	POST RequestMethod = "POST"
	GET  RequestMethod = "GET"
	PUT  RequestMethod = "PUT"
)

type RequestOptions

type RequestOptions func(*Request)

func SetContentType

func SetContentType(content RequestContentType) RequestOptions

func SetHeader

func SetHeader(Header map[string]string) RequestOptions

func SetMethod

func SetMethod(method RequestMethod) RequestOptions

func SetParams

func SetParams(Params ReqParams) RequestOptions

func SetRawQuery

func SetRawQuery(RawQuery string) RequestOptions

Jump to

Keyboard shortcuts

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