utils

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsurePathAt added in v0.5.4

func EnsurePathAt(path, defaultFilename string, perm int, vfs ...storage.VirtualFS) (at string, err error)

EnsurePathAt ensures that the specified path exists (including any non existing intermediate directories). Given a path and a default filename, the specified path is created in the following manner: - If the path denotes a file (path does not end is a directory separator), then the parent folder is created if it doesn't exist on the file-system provided. - If the path denotes a directory, then that directory is created.

The returned string represents the file, so if the path specified was a directory path, then the defaultFilename provided is joined to the path and returned, otherwise the original path is returned un-modified. Note: filepath.Join does not preserve a trailing separator, therefore to make sure a path is interpreted as a directory and not a file, then the separator has to be appended manually onto the end of the path. If vfs is not provided, then the path is ensured directly on the native file system.

func Exists

func Exists(path string) bool

Exists provides a simple way to determine whether the item identified by a path actually exists either as a file or a folder

func FileExists

func FileExists(path string) bool

FileExists provides a simple way to determine whether the item identified by a path actually exists as a file

func FolderExists

func FolderExists(path string) bool

FileExists provides a simple way to determine whether the item identified by a path actually exists as a folder

func IsNil

func IsNil(i interface{}) bool

func Must added in v0.1.5

func Must(err error)

Must

func ResolvePath added in v0.2.0

func ResolvePath(path string, mocks ...ResolveMocks) string

ResolvePath performs 2 forms of path resolution. The first is resolving a home path reference, via the ~ character; ~ is replaced by the user's home path. The second resolves ./ or ../ relative path. The overrides do not need to be provided.

func SplitParent

func SplitParent(path string) (d, f string)

Types

type AbsFunc added in v0.2.0

type AbsFunc func(path string) (string, error)

AbsFunc signature of function used to obtain the absolute representation of a path.

func (AbsFunc) Abs added in v0.2.0

func (f AbsFunc) Abs(path string) (string, error)

Abs function invoker, allows a function to be used in place where an instance of an interface would be expected.

type HomeUserFunc added in v0.2.0

type HomeUserFunc func() (string, error)

HomeUserFunc signature of function used to obtain the user's home directory.

func (HomeUserFunc) Home added in v0.2.0

func (f HomeUserFunc) Home() (string, error)

Home function invoker, allows a function to be used in place where an instance of an interface would be expected.

type PutProp

type PutProp[T any] interface {
	RwProp[T]
	Put(value T)
}

PutProp putter variable property interface. The putter allows the client to define assignment using a client defined function. The putter will still set the property's Field value.

func NewPutProp

func NewPutProp[T any](value T, putter func(value T)) PutProp[T]

NewPutProp create putter variable property

func NewPutPropZ

func NewPutPropZ[T any](value T, putter func(value T)) PutProp[T]

NewPutProp create putter variable and zeroable property

type PutPropFactory

type PutPropFactory[T any] struct {
	Zeroable bool
}

PutPropFactory putter variable property factory

func (PutPropFactory[T]) New

func (f PutPropFactory[T]) New(value T, putter func(value T)) PutProp[T]

New putter variable property constructor

type ResolveMocks added in v0.2.0

type ResolveMocks struct {
	HomeFunc HomeUserFunc
	AbsFunc  AbsFunc
}

ResolveMocks, used to override the internal functions used to resolve the home path (os.UserHomeDir) and the abs path (filepath.Abs). In normal usage, these do not need to be provided, just used for testing purposes.

type RoProp

type RoProp[T any] interface {
	Get() T
	IsNone() bool
}

RoProp const property interface.

func NewRoProp

func NewRoProp[T any](value T) RoProp[T]

NewRoProp create const property

type RoPropFactory

type RoPropFactory[T any] struct {
	Zeroable bool
}

RoPropFactory const property factory

func (RoPropFactory[T]) New

func (f RoPropFactory[T]) New(value T) RoProp[T]

New const property constructor

type RwProp

type RwProp[T any] interface {
	RoProp[T]
	Set(value T)
	IsZeroable() bool
	RoRef() RoProp[T]
}

RwProp variable property interface

func NewRwProp

func NewRwProp[T any](value T) RwProp[T]

NewRwProp create variable property

func NewRwPropZ

func NewRwPropZ[T any](value T) RwProp[T]

NewRwProp create variable and zeroable property

type RwPropFactory

type RwPropFactory[T any] struct {
	Zeroable bool
}

RwPropFactory variable property factory

func (RwPropFactory[T]) New

func (f RwPropFactory[T]) New(value T) RwProp[T]

New variable property constructor

type VarProp

type VarProp[T any] struct {
	Field T
	// contains filtered or unexported fields
}

VarProp a read/write property

func (*VarProp[T]) Get

func (p *VarProp[T]) Get() T

Get property value getter

func (*VarProp[T]) IsNone

func (p *VarProp[T]) IsNone() bool

IsNone determines whether the property has a value set

func (*VarProp[T]) IsZeroable

func (p *VarProp[T]) IsZeroable() bool

IsZeroable indicates whether a zero value is a valid value for this property

func (*VarProp[T]) RoRef

func (p *VarProp[T]) RoRef() RoProp[T]

RoRef returns a read only reference to this property

func (*VarProp[T]) Set

func (p *VarProp[T]) Set(value T)

Set property value setter

Jump to

Keyboard shortcuts

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