Rename app to radiantwave: embed and provision assets, drop proclamations
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// Package assets provisions the static assets bundled into the binary
|
||||
// (fonts, shaders, and terms-of-service pages) into a per-user assets
|
||||
// directory at application startup.
|
||||
package assets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Provision copies every file from the embedded filesystem into destDir,
|
||||
// preserving the relative directory structure. Existing files are
|
||||
// overwritten so the deployed assets always match the running binary.
|
||||
func Provision(bundled fs.FS, destDir string) error {
|
||||
return fs.WalkDir(bundled, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
src, err := bundled.Open(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening bundled asset %s: %w", path, err)
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst := filepath.Join(destDir, filepath.FromSlash(path))
|
||||
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
||||
return fmt.Errorf("creating asset directory for %s: %w", path, err)
|
||||
}
|
||||
|
||||
out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating asset file %s: %w", dst, err)
|
||||
}
|
||||
if _, err := io.Copy(out, src); err != nil {
|
||||
out.Close()
|
||||
return fmt.Errorf("writing asset file %s: %w", dst, err)
|
||||
}
|
||||
if err := out.Close(); err != nil {
|
||||
return fmt.Errorf("closing asset file %s: %w", dst, err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user