Documentation ¶
Index ¶
- func ConvertMapToQueryString(param map[string]any) string
- func DownloadFile(filepath string, url string) error
- func EncodeUrl(urlStr string) (string, error)
- func GetInternalIp() string
- func GetIps() []string
- func GetMacAddrs() []string
- func GetRequestPublicIp(req *http.Request) string
- func HttpDelete(url string, params ...any) (*http.Response, error)
- func HttpGet(url string, params ...any) (*http.Response, error)
- func HttpPatch(url string, params ...any) (*http.Response, error)
- func HttpPost(url string, params ...any) (*http.Response, error)
- func HttpPut(url string, params ...any) (*http.Response, error)
- func IsInternalIP(IP net.IP) bool
- func IsPingConnected(host string) bool
- func IsPublicIP(IP net.IP) bool
- func IsTelnetConnected(host string, port string) bool
- func ParseHttpResponse(resp *http.Response, obj any) error
- func StructToUrlValues(targetStruct any) (url.Values, error)
- func UploadFile(filepath string, server string) (bool, error)
- type File
- type HttpClient
- type HttpClientConfig
- type HttpRequest
- type PublicIpInfo
- type SetFileFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMapToQueryString ¶
ConvertMapToQueryString convert map to sorted url query string. Play: https://go.dev/play/p/jnNt_qoSnRi
func DownloadFile ¶
DownloadFile will download the file exist in url to a local file.
func GetRequestPublicIp ¶
GetRequestPublicIp return the requested public ip.
func HttpDelete ¶
HttpDelete send delete http request.
func IsPingConnected ¶
IsPingConnected checks if can ping specified host or not.
func IsTelnetConnected ¶
IsTelnetConnected checks if can telnet specified host or not.
func ParseHttpResponse ¶
ParseHttpResponse decode http response to specified interface.
func StructToUrlValues ¶
StructToUrlValues convert struct to url valuse, only convert the field which is exported and has `json` tag.
Types ¶
type HttpClient ¶
type HttpClient struct { *http.Client TLS *tls.Config Request *http.Request Config HttpClientConfig }
HttpClient is used for sending http request
func NewHttpClientWithConfig ¶
func NewHttpClientWithConfig(config *HttpClientConfig) *HttpClient
NewHttpClientWithConfig make a HttpClient instance with pass config
func (*HttpClient) DecodeResponse ¶
func (client *HttpClient) DecodeResponse(resp *http.Response, target any) error
DecodeResponse decode response into target object. Play: https://go.dev/play/p/jUSgynekH7G
func (*HttpClient) SendRequest ¶
func (client *HttpClient) SendRequest(request *HttpRequest) (*http.Response, error)
SendRequest send http request. Play: https://go.dev/play/p/jUSgynekH7G
type HttpClientConfig ¶
type HttpClientConfig struct { SSLEnabled bool TLSConfig *tls.Config Compressed bool HandshakeTimeout time.Duration ResponseTimeout time.Duration Verbose bool }
HttpClientConfig contains some configurations for http client
type HttpRequest ¶
type HttpRequest struct { RawURL string Method string Headers http.Header QueryParams url.Values FormData url.Values File *File Body []byte }
HttpRequest struct is a composed http request
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.