Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leaanthony/debme
embed.FS wrapper providing additional functionality
https://github.com/leaanthony/debme
golang
Last synced: about 2 months ago
JSON representation
embed.FS wrapper providing additional functionality
- Host: GitHub
- URL: https://github.com/leaanthony/debme
- Owner: leaanthony
- License: mit
- Created: 2021-04-16T00:25:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-06-06T02:03:03.000Z (over 3 years ago)
- Last Synced: 2024-10-14T08:45:13.243Z (about 2 months ago)
- Topics: golang
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 32
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - debme - Create an `embed.FS` from an existing `embed.FS` subdirectory. (Resource Embedding / HTTP Clients)
- zero-alloc-awesome-go - debme - Create an `embed.FS` from an existing `embed.FS` subdirectory. (Resource Embedding / HTTP Clients)
- awesome-go-extra - debme - 04-16T00:25:13Z|2021-06-06T02:03:03Z| (Resource Embedding / HTTP Clients)
README
embed.FS
wrapper providing additional functionality
## Features
* Get an `embed.FS` from an embedded subdirectory
* Handy `Copy(sourcePath, targetPath)` method to copy an embedded file to the filesystem
* 100% `embed.FS` compatible
* 100% code coverage## Example
```go
package mainimport (
"embed"
"github.com/leaanthony/debme"
"io/fs"
)// Example Filesystem:
//
// fixtures/
// ├── test1
// | └── onefile.txt
// └── test2
// └── inner
// ├── deeper
// | └── three.txt
// ├── one.txt
// └── two.txt//go:embed fixtures
var fixtures embed.FSfunc main() {
root, _ := debme.FS(fixtures, "fixtures")// Anchor to "fixtures/test1"
test1, _ := root.FS("test1")
files1, _ := test1.ReadDir(".")println(len(files1)) // 1
println(files1[0].Name()) // "onefile.txt"// Anchor to "fixtures/test2/inner"
inner, _ := root.FS("test2/inner")
one, _ := inner.ReadFile("one.txt")println(string(one)) // "1"
// Fully compatible FS
fs.WalkDir(inner, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
println("Path:", path, " Name:", d.Name())
return nil
})/*
Path: . Name: inner
Path: deeper Name: deeper
Path: deeper/three.txt Name: three.txt
Path: one.txt Name: one.txt
Path: two.txt Name: two.txt
*/
// Go deeper
deeper, _ := inner.FS("deeper")
deeperFiles, _ := deeper.ReadDir(".")println(len(deeperFiles)) // 1
println(files1[0].Name()) // "three.txt"
// Copy files
err := deeper.Copy("three.txt", "/path/to/target.txt")
}
```## Why
Go's new embed functionality is awesome! The only thing I found a little frustrating was the need to manage base paths.
This module was created out of the need to embed multiple templates in the [Wails](https://github.com/wailsapp/wails) CLI.