Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oppodelldog/filediscovery
go module that helps to find a file in various places
https://github.com/oppodelldog/filediscovery
command-line configuration configuration-files filesystem go golang
Last synced: 5 days ago
JSON representation
go module that helps to find a file in various places
- Host: GitHub
- URL: https://github.com/oppodelldog/filediscovery
- Owner: Oppodelldog
- License: mit
- Created: 2018-03-17T04:38:30.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2023-04-01T12:23:47.000Z (almost 2 years ago)
- Last Synced: 2024-11-17T12:09:41.513Z (about 2 months ago)
- Topics: command-line, configuration, configuration-files, filesystem, go, golang
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Report Card](https://goreportcard.com/badge/github.com/Oppodelldog/filediscovery)](https://goreportcard.com/report/github.com/Oppodelldog/filediscovery)
[![Coverage Status](https://coveralls.io/repos/github/Oppodelldog/filediscovery/badge.svg)](https://coveralls.io/github/Oppodelldog/filediscovery)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://raw.githubusercontent.com/Oppodelldog/filediscovery/master/LICENSE)
[![Build Status](https://travis-ci.com/Oppodelldog/filediscovery.svg?branch=master)](https://travis-ci.com/Oppodelldog/filediscovery)
[![pkg.go.dev](https://img.shields.io/badge/pkg.go.dev-reference-%23007d9c.svg)](https://pkg.go.dev/github.com/Oppodelldog/filediscovery)# Filediscovery
> this module helps to find a file in various file locations## Example
See the example in [test/example_test.go](test/example_test.go).```go
//noinspection All
package mainimport "github.com/Oppodelldog/filediscovery/filediscovery"
func main(){
var envVarName = "MYAPP_CONFIG_FILE"fileLocationProviders := []filediscovery.FileLocationProvider{
filediscovery.WorkingDirProvider(),
filediscovery.ExecutableDirProvider(),
filediscovery.EnvVarFilePathProvider(envVarName),
filediscovery.HomeConfigDirProvider(".config","myapp"),
}
discovery := filediscovery.New(fileLocationProviders)
filePath, err := discovery.Discover("file_to_discover.yml")
_ , _= filePath,err
// filePath - contains the first existing file in sequential order of given file providers
// err - nil if file was found. if no file was found it displays helpful error information
}
```## Advanced
If you'd like to implement a custom file Provider, you just need to
implement the ```FileLoactionProvider``` function type.
Here's a sample demonstration:
```go
package main// type FileLocationProvider func(fileName string) (string, error)
//noinspection All
func myLocationProvider(filename string)(string, error){
somePath := "get it from your custom lookup strategy"return somePath,nil
}```