httpx

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpGet

func HttpGet[T any](ser IService, path string, sets ...Set) (res T, body []byte, err error)

func HttpJsonToObj

func HttpJsonToObj[T any](bs []byte) (res T, err error)

func HttpPost

func HttpPost[T any](ser IService, path string, in any, sets ...Set) (res T, body []byte, err error)

func ReadResponse

func ReadResponse(resp *http.Response) (res []byte, err error)

func ResponseToObj

func ResponseToObj[T any](resp *http.Response) (res T, bs []byte, err error)

Types

type Config

type Config struct {
	// Disabled 禁用 上层 初始化服务时候 可以判断该属性 如果为 配置 true 则不去初始化服务
	Disabled bool `json:"disabled,omitempty" yaml:"disabled,omitempty"`

	RootUrl string `json:"rootUrl" yaml:"rootUrl"`

	// 超时时间 单位 毫秒
	Timeout         int `json:"timeout" yaml:"timeout"`
	MaxIdleConns    int `json:"maxIdleConns" yaml:"maxIdleConns"`
	MaxConnsPerHost int `json:"maxConnsPerHost" yaml:"maxConnsPerHost"`
	// 超时时间 单位 毫秒
	IdleConnTimeout int `json:"idleConnTimeout" yaml:"idleConnTimeout"`

	Tls *TLSConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
	// contains filtered or unexported fields
}

func (*Config) GetConnProxy

func (this_ *Config) GetConnProxy() ConnProxy

func (*Config) SetConnProxy

func (this_ *Config) SetConnProxy(connProxy ConnProxy)

type ConnProxy

type ConnProxy interface {
	Dial(n string, addr string) (net.Conn, error)
}

type DataResponse

type DataResponse[T any] struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

func HttpPostDataResponse

func HttpPostDataResponse[T any](ser IService, path string, in any, sets ...Set) (res *DataResponse[T], body []byte, err error)

type IService

type IService interface {
	// Close 关闭 客户端
	Close()
	// Info 查看 zk 相关信息
	Info() (info *Info, err error)

	Request(method, url string, body io.Reader, sets ...Set) (resp *http.Response, err error)
	GetRequest(url string, sets ...Set) (resp *http.Response, err error)
	PostRequest(url string, body io.Reader, sets ...Set) (resp *http.Response, err error)
	GetUrl(path string) (res string)
	Get(path string, sets ...Set) (res []byte, err error)
	Post(path string, data any, sets ...Set) (res []byte, err error)
}

func New

func New(config *Config) (IService, error)

New 创建zookeeper客户端

type Info

type Info struct {
}

type Request

type Request struct {
	*http.Request
}

func (*Request) SetHeader

func (this_ *Request) SetHeader(name, value string) *Request

type Response

type Response struct {
	*http.Response
}

type Service

type Service struct {
	*Config
	// contains filtered or unexported fields
}

func (*Service) Close

func (this_ *Service) Close()

func (*Service) DataReader

func (this_ *Service) DataReader(data any) (res io.Reader, err error)

func (*Service) Get

func (this_ *Service) Get(path string, sets ...Set) (res []byte, err error)

func (*Service) GetRequest

func (this_ *Service) GetRequest(url string, sets ...Set) (resp *http.Response, err error)

func (*Service) GetUrl

func (this_ *Service) GetUrl(path string) (res string)

func (*Service) Info

func (this_ *Service) Info() (res *Info, err error)

func (*Service) Post

func (this_ *Service) Post(path string, data any, sets ...Set) (res []byte, err error)

func (*Service) PostRequest

func (this_ *Service) PostRequest(url string, body io.Reader, sets ...Set) (resp *http.Response, err error)

func (*Service) Request

func (this_ *Service) Request(method, url string, body io.Reader, sets ...Set) (resp *http.Response, err error)

type Set

type Set func(in *Request)

type TLSConfig

type TLSConfig struct {
	InsecureSkipVerify bool `json:"insecureSkipVerify" yaml:"insecureSkipVerify"`
}

Jump to

Keyboard shortcuts

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