snetutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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) Header

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

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 {
	// contains filtered or unexported fields
}

byte 形式的response

func (*HttpRespBytes) Marshal

func (m *HttpRespBytes) Marshal() (int, []byte)

type HttpRespJson

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

json形式的response

func (*HttpRespJson) Marshal

func (m *HttpRespJson) Marshal() (int, []byte)

type HttpRespString

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

string 形式的response

func (*HttpRespString) Marshal

func (m *HttpRespString) Marshal() (int, []byte)

type HttpResponse

type HttpResponse interface {
	Marshal() (int, []byte)
}

http response interface

func NewHttpRespBytes

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

func NewHttpRespJson

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

func NewHttpRespJson200

func NewHttpRespJson200(r interface{}) HttpResponse

func NewHttpRespString

func NewHttpRespString(status int, resp string) HttpResponse

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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