xnet

package
v0.0.0-...-b804f52 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func ClientPublicIP

func ClientPublicIP(r *http.Request) string

ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func HasLocalIP

func HasLocalIP(ip net.IP) bool

HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高,详见:https://github.com/thinkeridea/go-extend/issues/2

func HasLocalIPddr

func HasLocalIPddr(ip string) bool

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

func IP2Long

func IP2Long(ip net.IP) (uint, error)

IP2Long 把net.IP转为数值

func IPString2Long

func IPString2Long(ip string) (uint, error)

IPString2Long 把ip字符串转为数值

func Long2IP

func Long2IP(i uint) (net.IP, error)

Long2IP 把数值转为net.IP

func Long2IPString

func Long2IPString(i uint) (string, error)

Long2IPString 把数值转为ip字符串

func RemoteIP

func RemoteIP(r *http.Request) string

RemoteIP 通过 RemoteAddr 获取 IP 地址, 只是一个快速解析方法。

Types

type URL

type URL struct {
	Scheme     string
	Opaque     string        // encoded opaque data
	User       *url.Userinfo // username and password information
	Host       string        // host or host:port
	Path       string        // path (relative paths may omit leading slash)
	RawPath    string        // encoded path hint (see EscapedPath method)
	ForceQuery bool          // append a query ('?') even if RawQuery is empty
	RawQuery   string        // encoded query values, without '?'
	Fragment   string        // fragment for references, without '#'
	HostName   string
	Port       string
	// contains filtered or unexported fields
}

URL wrap url.URL.

func ParseURL

func ParseURL(raw string) (*URL, error)

ParseURL parses raw into URL.

func (*URL) Password

func (u *URL) Password() (string, bool)

Password gets password from URL.

func (*URL) Query

func (u *URL) Query() url.Values

Query parses RawQuery and returns the corresponding values. It silently discards malformed value pairs. To check errors use ParseQuery.

func (*URL) QueryBool

func (u *URL) QueryBool(field string, expect bool) (ret bool)

QueryBool returns provided field's value in bool if value is empty, expect returns

func (*URL) QueryDuration

func (u *URL) QueryDuration(field string, expect time.Duration) (ret time.Duration)

QueryDuration returns provided field's value in duration type. if value is empty, expect returns

func (*URL) QueryInt

func (u *URL) QueryInt(field string, expect int) (ret int)

QueryInt returns provided field's value in int type. if value is empty, expect returns

func (*URL) QueryInt64

func (u *URL) QueryInt64(field string, expect int64) (ret int64)

QueryInt64 returns provided field's value in int64 type. if value is empty, expect returns

func (*URL) QueryString

func (u *URL) QueryString(field string, expect string) (ret string)

QueryString returns provided field's value in string type. if value is empty, expect returns

func (*URL) Username

func (u *URL) Username() string

Username gets username from URL.

Jump to

Keyboard shortcuts

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