Documentation ¶
Overview ¶
Package util implements a set of util functions.
Index ¶
- func AddressCount(network *net.IPNet) uint64
- func AddressRange(network *net.IPNet) (net.IP, net.IP)
- func AesECBEncryptHex(key, message string) (string, error)
- func Base64Encode(data []byte) string
- func CheckFileExists(filename string) bool
- func Contains(slice []string, value string, caseInsensitive bool) bool
- func CreateRandomString() string
- func Debug(title, message string)
- func Dec(IP net.IP) net.IP
- func FormatTest(funcName, got, expected string) string
- func GetMD5(data interface{}, base64Encode bool) string
- func GetMapKey(m map[string]string, key string, caseInsensitive bool) string
- func GetMapValue(m map[string]string, key string, caseInsensitive bool) string
- func GetSha256(data interface{}) string
- func GetURIPath(uri string) string
- func GetURL(protocol, host, uriPath string, params map[string]string) string
- func GuessMimeType(s string) string
- func HmacSha256Hex(key, message string) string
- func HomeDir() (string, error)
- func Host(base *net.IPNet, num int) (net.IP, error)
- func HostToURL(host, protocol string) string
- func Inc(IP net.IP) net.IP
- func MapContains(m map[string]string, compareFunc func(string, string) bool) bool
- func MapKeyToLower(m map[string]string)
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func NextSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool)
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PreviousSubnet(network *net.IPNet, prefixLen int) (*net.IPNet, bool)
- func SliceToLower(slice []string)
- func Subnet(base *net.IPNet, newBits int, num int) (*net.IPNet, error)
- func TempFile(content []byte, dir, prefix string) (*os.File, error)
- func TempFileWithSize(fileSize int64) (*os.File, error)
- func TimeStringToRFC1123(str string) string
- func TimeToUTCString(t time.Time) string
- func ToCanonicalHeaderString(headerMap map[string]string) string
- func ToCanonicalQueryString(params map[string]string) string
- func ToJson(i interface{}, keys ...string) ([]byte, error)
- func ToMap(i interface{}, keys ...string) (map[string]interface{}, error)
- func URIEncodeExceptSlash(uri string) string
- func URLEncode(str string) string
- func VerifyNoOverlap(subnets []*net.IPNet, CIDRBlock *net.IPNet) error
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddressCount ¶
AddressCount returns the number of distinct host addresses within the given CIDR range.
Since the result is a uint64, this function returns meaningful information only for IPv4 ranges and IPv6 ranges with a prefix size of at least 65.
func AddressRange ¶
AddressRange returns the first and last addresses in the given CIDR range.
func AesECBEncryptHex ¶
AesECBEncryptHex returns an AES encrypted string
func Base64Encode ¶
Base64Encode gets base64 encoded string from data.
func CheckFileExists ¶
CheckFileExists checks if specified file exists.
func Contains ¶
Contains determines whether a string slice contains a certain value. Ignore case when comparing if case insensitive.
func FormatTest ¶
FormatTest returns a formatted string for unit test.
func GetMD5 ¶
GetMD5 gets the MD5 value from data. Param base64Encode determines whether use Base64Encode meanwhile.
func GetMapKey ¶
GetMapKey returns the key of the map for a certain value. Ignore case when comparing if case insensitive.
func GetMapValue ¶
GetMapValue returns the value of the map for a certain key. Ignore case when comparing if case insensitive.
func GuessMimeType ¶
GuessMimeType gets the MIME Type of a suffix string.
func HmacSha256Hex ¶
HmacSha256Hex returns a encrypted string.
func Host ¶
Host takes a parent CIDR range and turns it into a host IP address with the given host number.
For example, 10.3.0.0/16 with a host number of 2 gives 10.3.0.2.
func MapContains ¶
MapContains determines whether the string map contains a uncertain value. The result is determined by compare function.
func MapKeyToLower ¶
MapKeyToLower transforms each item of a map to lowercase.
func NewECBEncrypter ¶
NewECBEncrypter returns a ECBEncrypter
func NextSubnet ¶
NextSubnet returns the next available subnet of the desired mask size starting for the maximum IP of the offset subnet If the IP exceeds the maxium IP then the second return value is true
func PKCS7Padding ¶
PKCS7Padding returns a encrypted string.
func PreviousSubnet ¶
PreviousSubnet returns the subnet of the desired mask in the IP space just lower than the start of IPNet provided. If the IP space rolls over then the second return value is true
func SliceToLower ¶
func SliceToLower(slice []string)
SliceToLower transforms each item of a slice to lowercase.
func Subnet ¶
Subnet takes a parent CIDR range and creates a subnet within it with the given number of additional prefix bits and the given network number.
For example, 10.3.0.0/16, extended by 8 bits, with a network number of 5, becomes 10.3.5.0/24 .
func TempFileWithSize ¶
TempFileWithSize generates a temp file with specified size.
func TimeStringToRFC1123 ¶
TimeStringToRFC1123 returns a formatted string of `time.RFC1123` format.
func TimeToUTCString ¶
TimeToUTCString returns a utc string of a time instance.
func ToCanonicalHeaderString ¶
ToCanonicalHeaderString returns the canonicalized string.
func ToCanonicalQueryString ¶
ToCanonicalQueryString returns the canonicalized query string.
func URIEncodeExceptSlash ¶
URIEncodeExceptSlash encodes all characters of a string except the slash character.
Types ¶
This section is empty.
Notes ¶
Bugs ¶
see https://github.com/golang/go/issues/4013 use %20 instead of the + character for encoding a space