Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileDiscoverer ¶
type FileDiscoverer interface { // Discover tries to find the given fileName in all FileLocationProviders. The providers are checked in given sequence. // the first matching result will be returned. If the file could not be found and error is returned as if any other // error occurs. Discover(fileName string) (string, error) }
FileDiscoverer defines logic to discover a file.
func New ¶
func New(fileLocationProviders []FileLocationProvider) FileDiscoverer
New creates a new FileDiscoverer and takes a list of FileLocationProviders which specify possible location a given file will be searched in.
type FileDiscovery ¶
type FileDiscovery struct {
// contains filtered or unexported fields
}
func (*FileDiscovery) Discover ¶
func (fd *FileDiscovery) Discover(fileName string) (string, error)
Discover tries to find the given fileName in all FileLocationProviders. The providers are checked in given sequence. the first matching result will be returned. If the file could not be found and error is returned as if any other error occurs.
Example ¶
// for this demonstration we create a test file in /tmp testFilePath := "/tmp/test-file.yml" err := ioutil.WriteFile(testFilePath, []byte("test"), 0666) if err != nil { panic("error writing test file") } // Discovery needs at least one FileLocationProvider which provides a file location to search for. // There are already some providers available, but let's create a new one, for the sake of completion. // In this case the FileLocation provided will be the /tmp folder. tempDirLocationProvider := func(fileName string) (string, error) { someFileLocation := "/tmp" suggestedFilePath := path.Join(someFileLocation, fileName) return suggestedFilePath, nil } // create the discovery discovery := New( []FileLocationProvider{ tempDirLocationProvider, }, ) // search the file fileFoundAtPath, _ := discovery.Discover("test-file.yml") // we receive the full path of the file found in /tmp fmt.Println(fileFoundAtPath)
Output: /tmp/test-file.yml
type FileLocationProvider ¶
FileLocationProvider provides a possible file location to FileDiscoverer
func EnvVarFilePathProvider ¶
func EnvVarFilePathProvider(envVar string) FileLocationProvider
EnvVarFilePathProvider provides a filePath in the given environment variable. In contrast to other FileLocationProviders, this file location provider expects a complete filePath in the given environment variable.
func ExecutableDirProvider ¶
func ExecutableDirProvider(subFolders ...string) FileLocationProvider
ExecutableDirProvider provides the executables directory as a possible file location
func HomeConfigDirProvider ¶
func HomeConfigDirProvider(subFolders ...string) FileLocationProvider
HomeConfigDirProvider provides the working directory as a possible file location
func WorkingDirProvider ¶
func WorkingDirProvider(subFolders ...string) FileLocationProvider
WorkingDirProvider provides the working directory as a possible file location