restgo

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

restgo

Documentation

Index

Constants

View Source
const (
	GET    = HttpMethod("GET")
	POST   = HttpMethod("POST")
	PUT    = HttpMethod("PUT")
	DELETE = HttpMethod("DELETE")

	ApplicationJson = ContentType("application/json")
	FormData        = ContentType("multipart/form-data")
	FormDataEncoded = ContentType("application/x-www-form-urlencoded")
	OctetStream     = ContentType("binary/octet-stream")
)

Variables

View Source
var ConsolePrint = func(curl string) {
	fmt.Println(curl)
}

Functions

func NewDefaultRestGo added in v1.0.1

func NewDefaultRestGo(cli *http.Client, trace *httptrace.ClientTrace) *defaultRestGo

Types

type AnyFunc

type AnyFunc func() interface{}

type Builder

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

func NewRestGoBuilder

func NewRestGoBuilder() *Builder

func (*Builder) BaseUrl

func (builder *Builder) BaseUrl(baseURL string) *Builder

func (*Builder) BodyPayload

func (builder *Builder) BodyPayload(body []byte) *Builder

BodyPayload 不做任何格式化,直接作为body传递

func (*Builder) ContentType

func (builder *Builder) ContentType(contentType ContentType) *Builder

func (*Builder) CtxSend

func (builder *Builder) CtxSend(ctx context.Context, method HttpMethod, url string) (Response, error)

func (*Builder) CtxSendWithRetry

func (builder *Builder) CtxSendWithRetry(ctx context.Context, method HttpMethod, url string, resF func(respW Response, err error) error, ops ...retry.Option) (Response, error)

func (*Builder) Curl

func (builder *Builder) Curl(curlConsumer func(curl string)) *Builder

func (*Builder) CustomRestGo

func (builder *Builder) CustomRestGo(customRestGo RestGo) *Builder

func (*Builder) File

func (builder *Builder) File(key, path string) *Builder

func (*Builder) FileReader

func (builder *Builder) FileReader(key, filename string, reader io.Reader) *Builder

FileReader 另外一种上传文件的方式,手动指定reader,如果同时设置调用了 File 方法,那么 File 方法中的参数会优先

func (*Builder) HeaderFunc

func (builder *Builder) HeaderFunc(hf SFunc) *Builder

HeaderFunc 通过函数计算需要传递的header选项

func (*Builder) Headers

func (builder *Builder) Headers(headers map[string]string, conditionFuncs ...ConditionFunc) *Builder

func (*Builder) PathVariable

func (builder *Builder) PathVariable(pathVal map[string]string) *Builder

PathVariable 路径参数

func (*Builder) Payload

func (builder *Builder) Payload(body interface{}) *Builder

Payload 请求载荷,根据设置的Content-Type确定最终发送形式

func (*Builder) PayloadFunc

func (builder *Builder) PayloadFunc(pf AnyFunc) *Builder

PayloadFunc 通过函数计算需要传递的payload

func (*Builder) Query

func (builder *Builder) Query(queryVal map[string]string) *Builder

Query URL拼接参数

func (*Builder) RspUnmarshal

func (builder *Builder) RspUnmarshal(v interface{}) *Builder

RspUnmarshal 对响应体进行反序列化,响应体为JSON形式 如果只关心响应体序列化到结构体的结果,通过设置这个可以减少代码的编写量

func (*Builder) Send

func (builder *Builder) Send(method HttpMethod, url string) (Response, error)

func (*Builder) SendWithRetry

func (builder *Builder) SendWithRetry(method HttpMethod, url string, resF func(respW Response, err error) error, ops ...retry.Option) (Response, error)

type ConditionFunc

type ConditionFunc func() (string, string)

type ContentType

type ContentType string

type HttpMethod

type HttpMethod string

type IResponse

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

func (*IResponse) Body

func (wrapper *IResponse) Body() []byte

func (*IResponse) BodyStr

func (wrapper *IResponse) BodyStr() string

func (*IResponse) BodyUnmarshal

func (wrapper *IResponse) BodyUnmarshal(v interface{}) error

func (*IResponse) Header

func (wrapper *IResponse) Header(key string) string

func (*IResponse) Proto

func (wrapper *IResponse) Proto() string

func (*IResponse) ProtoMajor

func (wrapper *IResponse) ProtoMajor() int

func (*IResponse) ProtoMinor

func (wrapper *IResponse) ProtoMinor() int

func (*IResponse) Status

func (wrapper *IResponse) Status() string

Status 获取http状态码

func (*IResponse) StatusCode

func (wrapper *IResponse) StatusCode() int

type Map

type Map map[string]interface{}

type Response

type Response interface {
	Header(key string) string
	BodyStr() string
	Body() []byte
	BodyUnmarshal(v interface{}) error
	Status() string
	StatusCode() int
	Proto() string
	ProtoMajor() int
	ProtoMinor() int
}

type RestGo

type RestGo interface {
	Do(ctx context.Context, url string, method string, body *bytes.Buffer, contentType string, headers map[string]string) (Response, error)
}

type SFunc

type SFunc func() map[string]string

type SMap

type SMap map[string]string

Jump to

Keyboard shortcuts

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