utilHttp

package
v0.0.0-...-5f3621a Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MulanPSL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const PROXY_TYPE_SOCKS5 = "socks5"

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request, debug ...bool) string

func ClientPublicIP

func ClientPublicIP(r *http.Request, debug ...bool) string

func HasLocalIP

func HasLocalIP(ip net.IP) bool

HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高

func HasLocalIPAddr

func HasLocalIPAddr(ip string) bool

HasLocalIPAddr 检测 IP 地址字符串是否是内网地址

func Request

func Request(method string, remoteUrl string, params url.Values, headers map[string]string, timeout ...time.Duration) (resp *http.Response, err error)

func RequestJson

func RequestJson(v interface{}, method string, remoteUrl string, params url.Values, headers map[string]string, timeout ...time.Duration) error

Types

type Paginator

type Paginator struct {
	Request     *http.Request `json:"-"`
	PerPage     int           `json:"per_page"`
	CurrentPage int           `json:"current_page"`
	MaxPages    int           `json:"-"`

	Total     int64 `json:"total"`
	PageRange []int `json:"page_range"`
	PageNums  int   `json:"page_nums"`
}

func NewPaginator

func NewPaginator(req *http.Request, per int, total interface{}) *Paginator

func (*Paginator) GetCurrentPage

func (p *Paginator) GetCurrentPage() int

func (*Paginator) GetPageNums

func (p *Paginator) GetPageNums() int

func (*Paginator) GetPages

func (p *Paginator) GetPages() []int

func (*Paginator) GetTotal

func (p *Paginator) GetTotal() int64

func (*Paginator) HasNext

func (p *Paginator) HasNext() bool

func (*Paginator) HasPages

func (p *Paginator) HasPages() bool

func (*Paginator) HasPrev

func (p *Paginator) HasPrev() bool

func (*Paginator) IsActive

func (p *Paginator) IsActive(page int) bool

func (*Paginator) Offset

func (p *Paginator) Offset() int
func (p *Paginator) PageLink(page int) string

func (*Paginator) PageLinkFirst

func (p *Paginator) PageLinkFirst() (link string)

func (*Paginator) PageLinkLast

func (p *Paginator) PageLinkLast() (link string)

func (*Paginator) PageLinkNext

func (p *Paginator) PageLinkNext() (link string)

func (*Paginator) PageLinkPrev

func (p *Paginator) PageLinkPrev() (link string)

func (*Paginator) SetTotal

func (p *Paginator) SetTotal(total interface{})

type UtilHttp

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

func New

func New(baseUrl string, timeout ...time.Duration) (uh *UtilHttp)

func (*UtilHttp) AddHeader

func (uh *UtilHttp) AddHeader(k string, v string) *UtilHttp

func (*UtilHttp) BasicAuth

func (uh *UtilHttp) BasicAuth(user string, password string) *UtilHttp

func (*UtilHttp) BuildRemoteUrl

func (uh *UtilHttp) BuildRemoteUrl(method string, path string, params *url.Values) (remoteUrl string, err error)

func (*UtilHttp) GetLastRespStatusCode

func (uh *UtilHttp) GetLastRespStatusCode() int

func (*UtilHttp) PostFile

func (uh *UtilHttp) PostFile(path string, filedName string, file string, params url.Values, headers map[string]string) (resp *http.Response, err error)

func (*UtilHttp) PostFileJson

func (uh *UtilHttp) PostFileJson(v interface{}, path string, filedName string, file string, params url.Values, headers map[string]string) error

func (*UtilHttp) PostFilePlain

func (uh *UtilHttp) PostFilePlain(path string, filedName string, file string, params url.Values, headers map[string]string) (body []byte, err error)

func (*UtilHttp) Request

func (uh *UtilHttp) Request(method string, path string, params url.Values, headers map[string]string) (resp *http.Response, err error)

func (*UtilHttp) RequestJson

func (uh *UtilHttp) RequestJson(v interface{}, method string, path string, params url.Values, headers map[string]string) error

func (*UtilHttp) RequestPlain

func (uh *UtilHttp) RequestPlain(method string, path string, params url.Values, headers map[string]string) (body []byte, err error)

func (*UtilHttp) SetBaseUrl

func (uh *UtilHttp) SetBaseUrl(baseUrl string) *UtilHttp

func (*UtilHttp) SetClientCertPemContent

func (uh *UtilHttp) SetClientCertPemContent(pemContent []byte, key []byte) *UtilHttp

func (*UtilHttp) SetClientCertPemPath

func (uh *UtilHttp) SetClientCertPemPath(path string) *UtilHttp

func (*UtilHttp) SetSslVerify

func (uh *UtilHttp) SetSslVerify(v bool) *UtilHttp

func (*UtilHttp) SetTimeout

func (uh *UtilHttp) SetTimeout(timeout time.Duration) *UtilHttp

func (*UtilHttp) UseProxySocks5

func (uh *UtilHttp) UseProxySocks5(proxyAddr string, proxyUser string, proxyPassword string) *UtilHttp

Jump to

Keyboard shortcuts

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