Documentation
¶
Index ¶
- Constants
- Variables
- func CRLF() []byte
- func EnvVarDurationValWithDefault(varName string, defaultVal time.Duration) time.Duration
- func EnvVarIntVal(varName string) (int, bool)
- func EnvVarIntValWithDefault(varName string, defaultVal int) int
- func EnvVarStringWithDefault(varName string, defaultVal string) string
- func EnvVarSwitchEnabled(varName string) bool
- func FindRootFor(target PathFindTarget, tailElem ...string) (string, error)
- func FormatDuration(duration time.Duration) string
- func IsAdmin() (bool, error)
- func IsWindows() bool
- func LF() []byte
- func LineSep() []byte
- func MicroEqual(a, b metav1.MicroTime) bool
- func ThisExecutablePath() (string, error)
- func WithNewline(b []byte) []byte
- func Within(a, b time.Time, max time.Duration) bool
- type PathFindTarget
Constants ¶
const ( PermissionOwnerReadWriteOthersRead os.FileMode = 0644 PermissionOnlyOwnerReadWrite os.FileMode = 0600 PermissionOnlyOwnerReadWriteTraverse os.FileMode = 0700 // For directories PermissionDirectoryOthersRead os.FileMode = 0755 // For shared directories PermissionOnlyOwnerReadWriteExecute os.FileMode = 0700 // For files PermissionCheckEveryoneRead os.FileMode = 0004 // Everyone can read, used for checking permissions PermissionCheckEveryoneWrite os.FileMode = 0002 // Everyone can write, used for checking permissions PermissionCheckEveryoneExecute os.FileMode = 0001 // Everyone can execute, used for checking permissions // Bitmask combined with umask for creating directories. This represents the maximum possible default permissions // for a folder; the final default permissions are determined by masking (subtracting) the umask bits from these // bits. DefaultFolderBitmask os.FileMode = 0777 // Bitmask combined with umask for creating files. This represents the maximum possible default permissions for a // file; the final default permissions are determined by masking (subtracting) the umask bits from these bits. DefaultFileBitmask os.FileMode = 0666 // Default umask for creating files and directories. The umask represents permissions that should be denied // when using the default file and directory permissions. The umask is subtracted from the maximum possible // permissions, so a umask of 022 would result in default folder permissions of 0755 (0777 - 022) and default file // permissions of 0644 (0666 - 022). DefaultUmaskBitmask os.FileMode = 022 )
const ( // RFC3339 with millisecond precision, fixed width. // This is a template, not a literal example. In particular, "Z" stands for timezone designator, // which is either "Z" or "+hh:mm" or "-hh:mm". See below for the regex that defines the actual format. RFC3339MiliTimestampFormat = "2006-01-02T15:04:05.000Z07:00" RFC33339YearRegex = `\d{4}` RFC3339MonthRegex = `(0[1-9]|1[0-2])` RFC3339DayRegex = `(0[1-9]|[12][0-9]|3[01])` RFC3339HourRegex = `([01][0-9]|2[0-3])` RFC3339TimestampMinutesOrSecondsRegex = `([0-5][0-9])` RFC3339MillisecondRegex = `\d{3}` )
const (
MaxCopyFileSize = 50 * 1024 * 1024 // 50MB
)
Variables ¶
var ( RFC3339TimezoneRegex = fmt.Sprintf( `(Z|([+-]?%s:%s))`, RFC3339HourRegex, RFC3339TimestampMinutesOrSecondsRegex, ) // Matches a timestamp in RFC3339 format with millisecond precision. // See https://www.rfc-editor.org/rfc/rfc3339#section-5.6 for more details. RFC3339MiliTimestampRegex = fmt.Sprintf( `%s-%s-%sT%s:%s:%s.%s%s`, RFC33339YearRegex, RFC3339MonthRegex, RFC3339DayRegex, RFC3339HourRegex, RFC3339TimestampMinutesOrSecondsRegex, RFC3339TimestampMinutesOrSecondsRegex, RFC3339MillisecondRegex, RFC3339TimezoneRegex, ) )
Functions ¶
func EnvVarIntVal ¶
func EnvVarIntValWithDefault ¶
func EnvVarStringWithDefault ¶
func EnvVarSwitchEnabled ¶
Returns true if the environment variable "switch" is enabled. The environment variable is considered enabled if it is set to one of the "truthy" values: "1", "true", "on", or "yes".
func FindRootFor ¶
func FindRootFor(target PathFindTarget, tailElem ...string) (string, error)
Starting from current working directory, tries to walk up the directory hierarchy and find the root that ends with given path to file or directory. Returns the root path found, or error.
func FormatDuration ¶
Formats a duration into a human readable string. If this proves not enough, consider https://github.com/hako/durafmt
func MicroEqual ¶
Checks whether two metav1.MicroTime values can be considered equal. Due to serialization/deserialization, the values may have different represenation, and thus Equal() may return false even if they represent essentially the same time.
func ThisExecutablePath ¶
Returns the full path to the current executable.
func WithNewline ¶
Types ¶
type PathFindTarget ¶
type PathFindTarget int
const ( FileTarget PathFindTarget = 1 DirTarget PathFindTarget = 2 )