netutils

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateTimeout added in v1.0.0

func CalculateTimeout(fileLength int64, minRate, defaultMinRate rate.Rate, reservedTime time.Duration) time.Duration

CalculateTimeout calculates the timeout(in seconds) according to the fileLength and the min rate of network.

The 0 will be returned when both minRate and defaultMinRate both are <=0.

func ConvertHeaders

func ConvertHeaders(headers []string) map[string]string

ConvertHeaders converts headers from array type to map type for http request.

func ConvertTimeIntToString

func ConvertTimeIntToString(timestamp int64) (string, error)

ConvertTimeIntToString converts an int64 timestamp to a string time.

func ConvertTimeStringToInt

func ConvertTimeStringToInt(timeStr string) (int64, error)

ConvertTimeStringToInt converts a string time to an int64 timestamp.

func ExtractHost

func ExtractHost(hostAndPort string) string

ExtractHost extracts host ip from the giving string.

func FilterURLParam

func FilterURLParam(url string, filters []string) string

FilterURLParam filters request queries in URL. Eg: If you pass parameters as follows:

url: http://a.b.com/locate?key1=value1&key2=value2&key3=value3
filter: key2

and then you will get the following value as the return:

http://a.b.com/locate?key1=value1&key3=value3

func GetAllIPs

func GetAllIPs() (ipList []string, err error)

GetAllIPs returns all non-loopback IPV4 addresses.

func GetIPAndPortFromNode

func GetIPAndPortFromNode(node string, defaultPort int) (string, int)

GetIPAndPortFromNode returns ip and port by parsing the node value. It will return defaultPort as the value of port when the node is a string without port or with an illegal port.

func IsValidIP

func IsValidIP(ip string) bool

IsValidIP returns whether the string ip is a valid IP Address.

func IsValidURL

func IsValidURL(urlStr string) bool

IsValidURL returns whether the string url is a valid HTTP URL.

func NetLimit

func NetLimit() *rate.Rate

NetLimit parse speed of interface that it has prefix of eth.

Types

This section is empty.

Jump to

Keyboard shortcuts

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