utils

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Suffix used to denote elided strings.
	ElideSuffix string = "..."

	// Length of the elide suffix.
	ElideSuffixLen int = 3
)
View Source
const (
	// Character to use when padding strings.
	PadPadding string = " "
)

Variables

This section is empty.

Functions

func Elide added in v0.4.0

func Elide(str string, max int) string

Return a string that has been elided to the given length.

func FormatDuration added in v0.1.1

func FormatDuration(dur time.Duration) string

Format a time duration in pretty format.

Example, a duration of 72 minutes becomes "1 hour(s), 12 minute(s)".

func GetEnv added in v0.3.3

func GetEnv(key, def string) string

Look up the given key in the underlying operating system's environment and return its value.

Should the key not exist, then the given default value is returned instead.

func Pad added in v0.4.0

func Pad(str string, padding int) string

Pad the given string with the given number of spaces.

func Pop

func Pop(array []string) (string, []string)

Pop the last element from an array, returning the element and a copy of the original array with the last element removed.

func Substr

func Substr(input string, start int, length int) string

Return a substring of the given input string that starts at the given start point and has the given length.

Types

type Filesystem added in v0.4.1

type Filesystem struct {
	// contains filtered or unexported fields
}

Filesystem

Allow fort he checking of filesystem entities without having to open, stat, close continuously.

This is a wrapper around various methods from the `os` package that is designed to allow repeated querying without having to re-open and re-stat the entity.

If used within a struct, this will not provide any sort of live updates and it does not utilise `epoll` (or any other similar facility) to update if a file or directory structure changes.

Maybe one day it will facilitate live updates et al to track file changes, but that day is not today.

func NewFilesystem added in v0.4.1

func NewFilesystem(path string) *Filesystem

Create a new filesystem object.

func (*Filesystem) Exists added in v0.4.1

func (fs *Filesystem) Exists() bool

Does the entity exist?

func (*Filesystem) IsDirectory added in v0.4.1

func (fs *Filesystem) IsDirectory() bool

Is the entity a directory?

func (*Filesystem) IsExecutable added in v0.4.1

func (fs *Filesystem) IsExecutable() bool

Does the entity's permission bits include any type of "executable"?

func (*Filesystem) IsFile added in v0.4.1

func (fs *Filesystem) IsFile() bool

Is the entity a file?

func (*Filesystem) IsGroupExecutable added in v0.4.1

func (fs *Filesystem) IsGroupExecutable() bool

Does the entity's permission bits include "group executable"?

func (*Filesystem) IsOtherExecutable added in v0.4.1

func (fs *Filesystem) IsOtherExecutable() bool

Does the entity's permission bits include "other executable"?

func (*Filesystem) IsOwnerExecutable added in v0.4.1

func (fs *Filesystem) IsOwnerExecutable() bool

Does the entity's permission bits include "owner executable"?

func (*Filesystem) Mode added in v0.4.1

func (fs *Filesystem) Mode() os.FileMode

Return the entity's mode.

func (*Filesystem) Name added in v0.4.1

func (fs *Filesystem) Name() string

Return the entity's name.

func (*Filesystem) Size added in v0.4.1

func (fs *Filesystem) Size() int64

Return the entity's size.

Jump to

Keyboard shortcuts

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