2021-02-18 04:39:52 +00:00
|
|
|
# Overlay
|
2021-05-09 04:02:16 +00:00
|
|
|
|
2021-05-09 04:06:23 +00:00
|
|
|
[![Go Reference](https://pkg.go.dev/badge/go.jolheiser.com/overlay.svg)](https://pkg.go.dev/go.jolheiser.com/overlay)
|
2021-05-09 04:02:16 +00:00
|
|
|
|
2021-02-18 04:39:52 +00:00
|
|
|
Overlay File System
|
2021-02-17 04:57:59 +00:00
|
|
|
|
2021-02-18 04:39:52 +00:00
|
|
|
Overlay is an easy way to implement a file system in such a way that
|
2021-02-17 04:57:59 +00:00
|
|
|
production assets can be overridden by assets on disk.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
|
2021-02-18 04:39:52 +00:00
|
|
|
"go.jolheiser.com/overlay"
|
2021-02-17 04:57:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed assets
|
|
|
|
var assets embed.FS
|
|
|
|
|
|
|
|
func main() {
|
2021-02-18 04:39:52 +00:00
|
|
|
ofs, err := overlay.New("/var/lib/myapp/custom", assets)
|
2021-02-17 04:57:59 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
If `/var/lib/myapp/custom` has an `assets` sub-directory, this implementation works.
|
|
|
|
|
|
|
|
However, if `/var/lib/myapp/custom` matches the `assets` directory layout,
|
|
|
|
you can use `WithSub` like so...
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
|
2021-02-18 04:39:52 +00:00
|
|
|
"go.jolheiser.com/overlay"
|
2021-02-17 04:57:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed assets
|
|
|
|
var assets embed.FS
|
|
|
|
|
|
|
|
func main() {
|
2021-02-18 04:39:52 +00:00
|
|
|
ofs, err := overlay.New("/var/lib/myapp/custom", assets, overlay.WithSub("assets"))
|
2021-02-17 04:57:59 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
[MIT](LICENSE)
|