Documentation ¶
Index ¶
- Constants
- func DirExists(path string) bool
- func Exists(path string) bool
- func ExpandPath(path string) (string, error)
- func FileExists(path string) bool
- func GenerateGitVersion() string
- func GenerateVersionFile(version string)
- func GetLastModified(path string) (time.Time, error)
- func IsDomainName(address string) error
- func IsEphemeralPort(port int) bool
- func IsEphemeralPortString(port string) bool
- func IsIP(address string) bool
- func IsIPv4(address string) bool
- func IsIPv6(address string) bool
- func IsPort(port int) bool
- func IsPortString(port string) bool
- func IsPublicAddress(address string) error
- func IsPublicIP(address string) error
- func IsValidPublicAddress(address string) error
- func MakeDirs(path string, perm os.FileMode) error
- func ParseIP(address string) net.IP
- func ReadDir(path string) ([]string, error)
- func ReadFile(path string) ([]byte, error)
- func ReadGoMod() string
- func SearchDefaultLocations(defaultFileName string, defaultDirectory string) (string, error)
- func WriteFile(path string, data []byte, filePerm, dirPerm os.FileMode) error
- func WriteFileDef(path string, data []byte) error
Constants ¶
const ( // FilePerms is the default permissions for new files FilePerms = os.FileMode(0644) // DirPerms is the default permissions for new directory DirPerms = os.ModePerm )
Variables ¶
This section is empty.
Functions ¶
func DirExists ¶
DirExists checks if the directory at the path exists. It returns false if the directory does not exist or if it is a file.
func ExpandPath ¶
ExpandPath replaces the '~' character with the user's home directory and cleans the path using the following rules:
- Replace multiple Separator elements with a single one.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path, assuming Separator is '/'.
- The returned path ends in a slash only if it represents a root directory.
- Any occurrences of slash are replaced by Separator.
func FileExists ¶
FileExists checks if the file at the path exists. It returns false if the file does not exist or if it is a directory.
func GenerateGitVersion ¶
func GenerateGitVersion() string
GenerateGitVersion returns current Git version information.
func GenerateVersionFile ¶
func GenerateVersionFile(version string)
GenerateVersionFile is for version file generation consumed by higher-level repos.
func GetLastModified ¶ added in v0.0.4
GetLastModified returns the time the file was last modified.
func IsDomainName ¶ added in v0.0.4
IsDomainName returns an error if the domain name is not valid. Ports are allowed; if a port is present, then it is stripped. See https://tools.ietf.org/html/rfc1034#section-3.5 and https://tools.ietf.org/html/rfc1123#section-2. source: https://gist.github.com/chmike/d4126a3247a6d9a70922fc0e8b4f4013
func IsEphemeralPort ¶ added in v0.0.4
IsEphemeralPort determines if the port is ephemeral. An ephemeral port is any unreserved port, which is any value greater than 1024 (RFC 6056). Note that some ports in this range are still assigned. https://datatracker.ietf.org/doc/html/rfc6056#section-3.2
func IsEphemeralPortString ¶ added in v0.0.4
IsEphemeralPortString determines if the string is an ephemeral port.
func IsIP ¶ added in v0.0.4
IsIP determines if the given string is a valid IP address. Ports are allowed; if a port is present, then it is stripped.
func IsIPv4 ¶ added in v0.0.4
IsIPv4 determines if the given string is a valid IPv4 address. Ports are allowed; if a port is present, then it is stripped.
func IsIPv6 ¶ added in v0.0.4
IsIPv6 determines if the given string is a valid IPv6 address. Ports are allowed; if a port is present, then it is stripped.
func IsPortString ¶ added in v0.0.4
IsPortString determines if the string is a valid network port.
func IsPublicAddress ¶ added in v0.0.4
IsPublicAddress determines if the given address is a public IP address or domain name. Any strings that are not IP addresses are determined to be valid domain names; the validity of the domain is not checked. Ports are allowed; if a port is present, then it is stripped.
func IsPublicIP ¶ added in v0.0.4
IsPublicIP determines if the given string is a valid public IP address. The IP address may include a port. If the IP is invalid, then an error is returned specifying the reason. Otherwise, it returns nil. Ports are allowed; if a port is present, then it is stripped.
func IsValidPublicAddress ¶ added in v0.0.4
IsValidPublicAddress determines if the given address is a public IP address or domain name. It also checks the validity of the domain name. Ports are allowed; if a port is present, then it is stripped.
func MakeDirs ¶
MakeDirs expands and cleans the path and then creates all the folders in a path that do not exist.
func ParseIP ¶ added in v0.0.4
ParseIP returns the IP address as a net.IP object. Expects a valid IPv4 or IPv6 address. Ports are allowed; if a port is present, then it is stripped.
func ReadDir ¶ added in v0.0.4
ReadDir reads the named directory, returning all its directory entries sorted by filename.
func ReadFile ¶
ReadFile expands and cleans the specified path, reads the file, and returns its contents.
func SearchDefaultLocations ¶
SearchDefaultLocations searches for a file path in a default directory in a number of hard-coded paths, including the user's home folder and /etc/. If the file is found, then its full path is returned. Otherwise, the path is blank and an error is returned.
Note that defaultDirectory MUST be a relative path. By default, when checking the home directory, a "." is prepended to the defaultDirectory.
func WriteFile ¶
WriteFile creates any directories in the path that do not exist and write the specified data to the file.
func WriteFileDef ¶ added in v0.0.4
WriteFileDef creates any directories in the path that do not exist and write the specified data to the file using the default file and directory permissions.
Types ¶
This section is empty.