rebed

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

README

rebed

codecov Build Status Go Report Card go.dev reference Awesome

Recreate embedded filesystems from embed.FS type in current working directory.

Expose the files you've embedded in your binary so users can see and/or tinker with them. See where is this useful for an application example.

Five actions available:


//go:embed someFS/*
var bdFS embed.FS

// Just replicate folder Structure
rebed.Tree(bdFS,"")

// Make empty files
rebed.Touch(bdFS,"")

// Recreate entire FS
rebed.Write(bdFS,"")

// Recreate FS without modifying existing files
rebed.Patch(bdFS,"")

// Runs Patch if no conflicting file is found, else error.
err := rebed.Create(bdFS,"")

/* Walk allows you operate on each file as you wish */
Where is this useful?

You could theoretically embed your web development assets folder and deploy it. The binary could run from the working directory folder generated by rebed and users could modify the assets and change the website's look (to do this run rebed.Patch to not overwrite modified files). If asset files are lost or the site breaks, running rebed.Write replaces all files with original ones.

Contributing

I'll look at issues and pull requests. Add a clear explanation when doing so!

Documentation

Overview

Package rebed brings simple embedded file functionality to Go's new embed directive.

It can recreate the directory structure from the embed.FS type with or without the files it contains. This is useful to expose the filesystem to the end user so they may see and modify the files.

It also provides basic directory walking functionality for the embed.FS type.

Index

Constants

This section is empty.

Variables

View Source
var ErrExist error = os.ErrExist

ErrExist returned by Create when encountering a file conflict in filesystem creation

Functions

func Create

func Create(fsys embed.FS, outputPath string) error

Create attempts to recreate filesystem. It first checks that there be no matching files present and returns an error if there is an existing file conflict in outputPath.

Folders are not considered to conflict.

func Patch

func Patch(fsys embed.FS, outputPath string) error

Patch creates files which are missing in FS filesystem. Does not modify existing files

func Touch

func Touch(fsys embed.FS, outputPath string) error

Touch creates the target filesystem folder structure in the binary's current working directory with empty files. Does not modify already existing files.

func Tree

func Tree(fsys embed.FS, outputPath string) error

Tree creates the target filesystem folder structure.

func Walk

func Walk(fsys embed.FS, startPath string, f func(path string, de fs.DirEntry) error) error

Walk expects a relative path within fsys. f called on every file/directory found recursively.

f's first argument is the relative/absolute path to directory being scanned. "." as startPath will scan all files and folders.

Any error returned by f will cause Walk to return said error immediately.

func WalkDir

func WalkDir(fsys embed.FS, startPath string, f func(path string, de fs.DirEntry) error) error

WalkDir applies f to every file/folder in embedded directory fsys.

f's first argument is the relative/absolute path to directory being scanned.

func Write

func Write(fsys embed.FS, outputPath string) error

Write overwrites files of same path/name in binaries current working directory or creates new ones if not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL