netutil

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 10 Imported by: 41

Documentation

Overview

Package netutil implements some basic functions to send http request and get ip info. Note: HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `url` is required. HttpGet, HttpPost, HttpDelete, HttpPut, HttpPatch, function param `params` is variable, the order is: params[0] is header which type should be http.Header or map[string]string, params[1] is query string param which type should be url.Values or map[string]string, when content-type header is multipart/form-data or application/x-www-form-urlencoded params[2] is post body which type should be []byte. params[3] is http client which type should be http.Client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertMapToQueryString

func ConvertMapToQueryString(param map[string]any) string

ConvertMapToQueryString convert map to sorted url query string

func EncodeUrl added in v2.1.3

func EncodeUrl(urlStr string) (string, error)

EncodeUrl encode url

func GetInternalIp

func GetInternalIp() string

GetInternalIp return internal ipv4

func GetIps

func GetIps() []string

GetIps return all ipv4 of system

func GetMacAddrs

func GetMacAddrs() []string

GetMacAddrs get mac address

func GetRequestPublicIp added in v2.1.2

func GetRequestPublicIp(req *http.Request) string

GetRequestPublicIp return the requested public ip

func HttpDelete

func HttpDelete(url string, params ...any) (*http.Response, error)

HttpDelete send delete http request

func HttpGet

func HttpGet(url string, params ...any) (*http.Response, error)

HttpGet send get http request

func HttpPatch

func HttpPatch(url string, params ...any) (*http.Response, error)

HttpPatch send patch http request

func HttpPost

func HttpPost(url string, params ...any) (*http.Response, error)

HttpPost send post http request

func HttpPut

func HttpPut(url string, params ...any) (*http.Response, error)

HttpPut send put http request

func IsInternalIP added in v2.1.2

func IsInternalIP(IP net.IP) bool

IsInternalIP verify an ip is intranet or not

func IsPublicIP

func IsPublicIP(IP net.IP) bool

IsPublicIP verify a ip is public or not

func ParseHttpResponse

func ParseHttpResponse(resp *http.Response, obj any) error

ParseHttpResponse decode http response to specified interface

Types

type PublicIpInfo

type PublicIpInfo struct {
	Status      string  `json:"status"`
	Country     string  `json:"country"`
	CountryCode string  `json:"countryCode"`
	Region      string  `json:"region"`
	RegionName  string  `json:"regionName"`
	City        string  `json:"city"`
	Lat         float64 `json:"lat"`
	Lon         float64 `json:"lon"`
	Isp         string  `json:"isp"`
	Org         string  `json:"org"`
	As          string  `json:"as"`
	Ip          string  `json:"query"`
}

PublicIpInfo public ip info: country, region, isp, city, lat, lon, ip

func GetPublicIpInfo

func GetPublicIpInfo() (*PublicIpInfo, error)

GetPublicIpInfo return public ip information return the PublicIpInfo struct

Jump to

Keyboard shortcuts

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