util

package
v0.0.0-...-eae6339 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AuthTokenHeaderName http header for token transport
	AuthTokenHeaderName = "Authorization"
	// RegexpEmail check valid email
	RegexpEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
)

Functions

func BroadcastAddr

func BroadcastAddr(n *net.IPNet) net.IP

BroadcastAddr returns the last address in the given network, or the broadcast address.

func DirectoryExists

func DirectoryExists(name string) bool

DirectoryExists check if directory exists

func FileExists

func FileExists(name string) bool

FileExists check if file exists

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetAvailableIp

func GetAvailableIp(cidr string, reserved []string) (string, error)

GetAvailableIp search for an available ip in cidr against a list of reserved ips

func GetCleanAuthToken

func GetCleanAuthToken(c *gin.Context) string

func GetIpFromCidr

func GetIpFromCidr(cidr string) (string, error)

GetIpFromCidr get ip from cidr

func GetNetworkAddress

func GetNetworkAddress(cidr string) (string, error)

GetNetworkAddress gets the valid start of a subnet

func IsIPv6

func IsIPv6(address string) bool

IsIPv6 check if given ip is IPv6

func IsValidCidr

func IsValidCidr(cidr string) bool

IsValidCidr check if CIDR is valid

func IsValidIp

func IsValidIp(ip string) bool

IsValidIp check if ip is valid

func RandomString

func RandomString(n int) (string, error)

RandomString returns a securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func ReadFile

func ReadFile(path string) (bytes []byte, err error)

ReadFile file content

func WriteFile

func WriteFile(path string, bytes []byte) (err error)

WriteFile content to file

Types

This section is empty.

Jump to

Keyboard shortcuts

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