snetutil

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: BSD-3-Clause Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient *http.Client = &http.Client{
	Transport: &http.Transport{
		MaxIdleConnsPerHost: 128,
		MaxConnsPerHost:     1024,
	},
	Timeout: 0,
}

Functions

func DoWriteResponse

func DoWriteResponse(w http.ResponseWriter, header http.Header, cookies []*http.Cookie, status int, body io.Reader)

func GetExterIp

func GetExterIp() (string, error)

获取首个外网ip v4

func GetInterIp

func GetInterIp() (string, error)

func GetListenAddr

func GetListenAddr(a string) (string, error)

不指定host使用内网host 指定了就使用指定的,不管指定的是0.0.0.0还是内网或者外网

func GetServAddr

func GetServAddr(a net.Addr) (string, error)

func HttpRangeDownload

func HttpRangeDownload(geturl, fileName string, splitSize int, timeout time.Duration) (int, error)

func HttpReq

func HttpReq(url, method string, data []byte, timeout time.Duration) ([]byte, int, error)

func HttpReqGetOk

func HttpReqGetOk(url string, timeout time.Duration) ([]byte, error)

func HttpReqOk

func HttpReqOk(url, method string, data []byte, timeout time.Duration) ([]byte, error)

func HttpReqPost

func HttpReqPost(url string, data []byte, timeout time.Duration) ([]byte, int, error)

func HttpReqPostOk

func HttpReqPostOk(url string, data []byte, timeout time.Duration) ([]byte, error)

func HttpReqWithHead

func HttpReqWithHead(url, method string, heads map[string]string, data []byte, timeout time.Duration) ([]byte, int, error)

func HttpReqWithHeadOk

func HttpReqWithHeadOk(url, method string, heads map[string]string, data []byte, timeout time.Duration) ([]byte, error)

func IpAddrFromRemoteAddr

func IpAddrFromRemoteAddr(s string) string

Request.RemoteAddress contains port, which we want to remove i.e.: "[::1]:58292" => "[::1]"

func IpAddrPort

func IpAddrPort(s string) string

func IpAddressHttpClient

func IpAddressHttpClient(r *http.Request) string

获取http请求的client的地址

func IpBetween

func IpBetween(from, to, test net.IP) (bool, error)

func IpBetweenStr

func IpBetweenStr(from, to, test string) (bool, error)

func IsInterIp

func IsInterIp(ip string) (bool, error)

10.0.0.0/8:10.0.0.0~10.255.255.255 172.16.0.0/12:172.16.0.0~172.31.255.255 192.168.0.0/16:192.168.0.0~192.168.255.255

func NewreqArgs

func NewreqArgs(r keyGet) *reqArgs

func PackageSplit

func PackageSplit(conn net.Conn, readtimeout time.Duration, readCall func([]byte)) (bool, []byte, error)

func Packdata

func Packdata(data []byte) []byte

func PackdataPad

func PackdataPad(data []byte, pad byte) []byte

func UnPackdata

func UnPackdata(lenmin uint, lenmax uint, packBuff []byte, readCall func([]byte)) ([]byte, error)

最小的消息长度、最大消息长度,数据流,包回调 正常返回解析剩余的数据,nil 否则返回错误

Types

type FactoryHandleRequest

type FactoryHandleRequest func() HandleRequest

type HandleRequest

type HandleRequest interface {
	Handle(*HttpRequest) HttpResponse
}

type HttpRequest

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

============================ 没有body类的请求

func NewHttpRequest

func NewHttpRequest(r *http.Request, ps httprouter.Params) (*HttpRequest, error)

func NewHttpRequestJsonBody

func NewHttpRequestJsonBody(r *http.Request, ps httprouter.Params, js interface{}) (*HttpRequest, error)

func (*HttpRequest) Body

func (m *HttpRequest) Body() *reqBody

func (*HttpRequest) Cookies

func (m *HttpRequest) Cookies() *reqArgs

func (*HttpRequest) Header

func (m *HttpRequest) Header() http.Header

func (*HttpRequest) Headers

func (m *HttpRequest) Headers() *reqArgs

func (*HttpRequest) Method

func (m *HttpRequest) Method() string

func (*HttpRequest) Params

func (m *HttpRequest) Params() *reqArgs

func (*HttpRequest) Query

func (m *HttpRequest) Query() *reqArgs

func (*HttpRequest) RemoteAddr

func (m *HttpRequest) RemoteAddr() string

func (*HttpRequest) Request

func (m *HttpRequest) Request() *http.Request

func (*HttpRequest) URL

func (m *HttpRequest) URL() *url.URL

type HttpRespBytes

type HttpRespBytes struct {
	Status int
	Body   []byte

	Header  http.Header
	Cookies []*http.Cookie
}

byte 形式的response

func (*HttpRespBytes) WriteResponse

func (m *HttpRespBytes) WriteResponse(w http.ResponseWriter)

type HttpRespJson

type HttpRespJson struct {
	Status  int
	Body    interface{}
	Header  http.Header
	Cookies []*http.Cookie
}

json形式的response

func (*HttpRespJson) WriteResponse

func (m *HttpRespJson) WriteResponse(w http.ResponseWriter)

type HttpRespRedirect

type HttpRespRedirect struct {
	Status int
	Url    string
	R      *HttpRequest
}

redirect

func (*HttpRespRedirect) WriteResponse

func (m *HttpRespRedirect) WriteResponse(w http.ResponseWriter)

type HttpRespString

type HttpRespString struct {
	Status int
	Body   string

	Header  http.Header
	Cookies []*http.Cookie
}

string 形式的response

func (*HttpRespString) WriteResponse

func (m *HttpRespString) WriteResponse(w http.ResponseWriter)

type HttpResponse

type HttpResponse interface {
	WriteResponse(http.ResponseWriter)
}

http response interface

func NewHttpRespBytes

func NewHttpRespBytes(status int, body []byte) HttpResponse

func NewHttpRespJson

func NewHttpRespJson(status int, body interface{}) HttpResponse

func NewHttpRespJson200

func NewHttpRespJson200(body interface{}) HttpResponse

func NewHttpRespRedirect

func NewHttpRespRedirect(r *HttpRequest, status int, redirectUrl string) HttpResponse

func NewHttpRespString

func NewHttpRespString(status int, body string) HttpResponse

Directories

Path Synopsis
tst

Jump to

Keyboard shortcuts

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