Documentation
¶
Index ¶
- Variables
- func GetPath(root string) string
- func GetPaths(root string) []string
- func NormalizePaths(paths ...string) []string
- type Factory
- type Locator
- func AsOptional(l Locator) Locator
- func AsUnique(locator Locator) Locator
- func First(locators ...Locator) Locator
- func NewCharDeviceLocator(opts ...Option) Locator
- func NewDirectoryLocator(opts ...Option) Locator
- func NewExecutableLocator(logger logger.Interface, root string) Locator
- func NewFileLocator(opts ...Option) Locator
- func NewLibraryLocator(opts ...Option) Locator
- func NewSymlinkChainLocator(opts ...Option) Locator
- func NewSymlinkLocator(opts ...Option) Locator
- func WithEvaluatedSymlinks(locator Locator) Locator
- type LocatorMock
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound indicates that a specified pattern or file could not be found.
Functions ¶
func GetPath ¶
GetPath returns a colon-separated path value that can be used to set the PATH environment variable
func GetPaths ¶
GetPaths returns a list of paths for a specified root. These are constructed from the PATH environment variable, a default path list, and the supplied root.
func NormalizePaths ¶
NormalizePaths takes a list of paths and normalizes these. Each of the elements in the list is expanded, meaning that if it consists of strings separated by the platform-specific path separator, the element is converted to a list by splitting on the separator. This allows for the contents of envvironment variables such as `PATH` or `LD_LIBRARY_PATH` to be processed allongside other explicit strings.
Types ¶
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory defines a builder for locators.
func NewFactory ¶
func (Factory) NewFileLocator ¶
type Locator ¶
Locator defines the interface for locating files on a system.
func AsOptional ¶
AsOptional converts the specified Locator to a Locator that does not raise an error if no candidate can be found for a specified pattern.
func NewCharDeviceLocator ¶
NewCharDeviceLocator creates a Locator that can be used to find char devices at the specified root. A logger is also specified.
func NewDirectoryLocator ¶
NewDirectoryLocator creates a Locator that can be used to find directories at the specified root.
func NewExecutableLocator ¶
NewExecutableLocator creates a locator to fine executable files in the path. A logger can also be specified.
func NewFileLocator ¶
NewFileLocator creates a Locator that can be used to find files with the specified builder.
func NewLibraryLocator ¶
NewLibraryLocator creates a library locator using the specified options. If search paths (WithSearchPaths(path1, path2, ...)) are explicitly specified a library locator using these as absolute paths are used. Otherwise the library is constructed using the following ordering, returning the first successful result:
- attempt to locate the library / pattern using dlopen
- attempt to locate the library from a set of predefined search paths.
- attempt to locate the library from the ldcache.
func NewSymlinkChainLocator ¶
NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
func NewSymlinkLocator ¶
NewSymlinkLocator creats a locator that can be used for locating files through symlinks.
func WithEvaluatedSymlinks ¶
WithEvaluatedSymlinks wraps a locator in one that ensures that returned symlinks are resolved.
type LocatorMock ¶
type LocatorMock struct {
// LocateFunc mocks the Locate method.
LocateFunc func(s string) ([]string, error)
// contains filtered or unexported fields
}
LocatorMock is a mock implementation of Locator.
func TestSomethingThatUsesLocator(t *testing.T) {
// make and configure a mocked Locator
mockedLocator := &LocatorMock{
LocateFunc: func(s string) ([]string, error) {
panic("mock out the Locate method")
},
}
// use mockedLocator in code that requires Locator
// and then make assertions.
}
func (*LocatorMock) Locate ¶
func (mock *LocatorMock) Locate(s string) ([]string, error)
Locate calls LocateFunc.
func (*LocatorMock) LocateCalls ¶
func (mock *LocatorMock) LocateCalls() []struct { S string }
LocateCalls gets all the calls that were made to Locate. Check the length with:
len(mockedLocator.LocateCalls())
type Option ¶
type Option func(*Factory)
func WithFilter ¶
WithFilter sets the filter for the file locator The filter is called for each candidate file and candidates that return nil are considered.
func WithLogger ¶
WithLogger sets the logger for the file locator
func WithSearchPaths ¶
WithSearchPaths sets the search paths for the file locator.