lookup

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPath

func GetPath(root string) string

GetPath returns a colon-separated path value that can be used to set the PATH environment variable

func GetPaths

func GetPaths(root string) []string

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.

Types

type Locator

type Locator interface {
	Locate(string) ([]string, error)
}

Locator defines the interface for locating files on a system.

func NewCharDeviceLocator

func NewCharDeviceLocator(opts ...Option) Locator

NewCharDeviceLocator creates a Locator that can be used to find char devices at the specified root. A logger is also specified.

func NewDirectoryLocator

func NewDirectoryLocator(opts ...Option) Locator

NewDirectoryLocator creates a Locator that can be used to find directories at the specified root.

func NewExecutableLocator

func NewExecutableLocator(logger logger.Interface, root string) Locator

NewExecutableLocator creates a locator to fine executable files in the path. A logger can also be specified.

func NewFileLocator

func NewFileLocator(opts ...Option) Locator

NewFileLocator creates a Locator that can be used to find files with the specified options.

func NewLibraryLocator added in v1.12.0

func NewLibraryLocator(logger logger.Interface, root string) (Locator, error)

NewLibraryLocator creates a library locator using the specified logger.

func NewSymlinkChainLocator

func NewSymlinkChainLocator(opts ...Option) Locator

NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.

func NewSymlinkLocator

func NewSymlinkLocator(opts ...Option) Locator

NewSymlinkLocator creats a locator that can be used for locating files through symlinks.

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 added in v1.12.0

type Option func(*file)

Option defines a function for passing options to the NewFileLocator() call

func WithCount added in v1.12.0

func WithCount(count int) Option

WithCount sets the maximum number of candidates to discover

func WithFilter added in v1.12.0

func WithFilter(assert func(string) error) Option

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 added in v1.12.0

func WithLogger(logger logger.Interface) Option

WithLogger sets the logger for the file locator

func WithOptional added in v1.12.0

func WithOptional(optional bool) Option

WithOptional sets the optional flag for the file locator If the optional flag is set, the locator will not return an error if the file is not found.

func WithRoot added in v1.12.0

func WithRoot(root string) Option

WithRoot sets the root for the file locator

func WithSearchPaths added in v1.12.0

func WithSearchPaths(paths ...string) Option

WithSearchPaths sets the search paths for the file locator.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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