httpkit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAccept        = "Accept"
	HeaderAuthorization = "Authorization"
	HeaderContentType   = "Content-Type"
)
View Source
const (
	ContentText          = "text/plain; charset=utf-8"
	ContentJSON          = "application/json"
	ContentXML           = "application/xml"
	ContentForm          = "application/x-www-form-urlencoded"
	ContentStream        = "application/octet-stream"
	ContentMultipartForm = "multipart/form-data"
)

Variables

This section is empty.

Functions

func BindJSON

func BindJSON(r *http.Request, obj any) error

BindJSON 解析JSON请求体并校验

func BindProto

func BindProto(r *http.Request, msg proto.Message, protovalidate bool) error

BindProto 解析Proto请求体并校验

func Client

func Client() *resty.Client

func ContentType

func ContentType(h http.Header) string

func HttpForm

func HttpForm(ctx context.Context, url string, form url.Values, header ...http.Header) (resp *resty.Response, err error)

func HttpGet

func HttpGet(ctx context.Context, url string, query url.Values, header ...http.Header) (resp *resty.Response, err error)

func HttpPost

func HttpPost(ctx context.Context, url string, body any, header ...http.Header) (resp *resty.Response, err error)

func NewHttpClient

func NewHttpClient() *http.Client

NewHttpClient returns a http client

func ParseProto

func ParseProto(r *http.Request, msg proto.Message) error

ParseProto 解析Proto请求体

Types

type ApiResult

type ApiResult[T any] struct {
	Code    int    `json:"code"`
	Msg     string `json:"msg"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

func HttpFormX

func HttpFormX[T any](ctx context.Context, url string, form url.Values, header ...http.Header) (ret *ApiResult[T], err error)

func HttpGetX

func HttpGetX[T any](ctx context.Context, url string, query url.Values, header ...http.Header) (ret *ApiResult[T], err error)

func HttpPostX

func HttpPostX[T any](ctx context.Context, url string, body any, header ...http.Header) (ret *ApiResult[T], err error)

func (*ApiResult[T]) Error

func (r *ApiResult[T]) Error(ok int) error

Jump to

Keyboard shortcuts

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