Get an embed.FS from inside an embed.FS


embed.FS wrapper providing additional functionality

CodeFactor CodeFactor

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

package main

import (
	"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.FS

func 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 CLI.

Owner
Lea Anthony
Creator of Wails: https://wails.app. Co-creator of xbar: https://getxbar.com. Hardcore Gopher.
Lea Anthony
Similar Resources

this allows you to get the real link of without get tracked bit.ly

this allows you to get the real link of without get tracked bit.ly

check the real url from a url shortener (bit.ly) Also you can use it as an API example with deno const rawResponse = await fetch("https://anti-url-s

Feb 19, 2022

Redis-benchmark - Simple get, mget and pipelined get benchmark.

redis-benchmark Simple get, mget and pipelined get benchmark. Usage git clone https://github.com/Ali-A-A/redis-benchmark.git cd ./redis-benchmark dock

Dec 31, 2021

Get-latest - Get the latest repository version

Get-latest - Get the latest repository version

get-latest Get the latest repository version Usage routes for public repos - /:

Nov 30, 2022

Write your SQL queries in raw files with all benefits of modern IDEs, use them in an easy way inside your application with all the profit of compile time constants

About qry is a general purpose library for storing your raw database queries in .sql files with all benefits of modern IDEs, instead of strings and co

Dec 25, 2022

Run WASM tests inside your browser

wasmbrowsertest Run Go wasm tests easily in your browser. If you have a codebase targeting the wasm platform, chances are you would want to test your

Dec 16, 2022

A simple `fs.FS` implementation to be used inside tests.

testfs A simple fs.FS which is contained in a test (using testing.TB's TempDir()) and with a few helper methods. PS: This lib only works on Go 1.16+.

Mar 3, 2022

vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds

vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds

Website • Quickstart • Documentation • Blog • Twitter • Slack vcluster - Virtual Clusters For Kubernetes Lightweight & Low-Overhead - Based on k3s, bu

Jan 4, 2023

Know when GC runs from inside your golang code

gcnotifier gcnotifier provides a way to receive notifications after every run of the garbage collector (GC). Knowing when GC runs is useful to instruc

Dec 26, 2022

🐺 Garment retains a single connection pool for different database types used inside you application

🐺 Garment retains a single connection pool for different database types used inside you application

Garment A Thread Safe Connection Pooling. Garment retains a single connection pool for different database types used inside you application (MySQL, Re

Nov 9, 2022

Store private data inside a git repository.

git-private lets you store private data inside a git repo. A common use case is protecting files containing API keys et.c.

Nov 13, 2022

Utilities around dealing with images inside of game dev. Inspired by my hate for TGA.

Image Conversion Utilities around dealing with images inside of game dev. Inspired by my hate for TGA. Install go install ./cmd/imgconv Examples TGA

Oct 28, 2021

A pod scaler golang app that can scale replicas either inside of cluster or out of the cluster

pod-scaler A simple pod scaler golang application that can scale replicas via manipulating the deployment Technologies The project has been created us

Oct 24, 2021

Tis module used as base fo configuration apps.By default, it expands into the inside of the application.

Tis module used as base fo configuration apps.By default, it expands into the inside of the application. Also, module c reads a dictionary of secrets from the application directory by its AppName and extension json.

Dec 7, 2021

Simple plugin to enable the /flip command inside of Mattermost

Plugin Starter Template This plugin serves as a starting point for writing a Mattermost plugin. Feel free to base your own plugin off this repository.

Nov 4, 2021

Monitoring Go application inside docker container by InfluxDB, Telegraf, Grafana

Monitoring Go application inside docker container by InfluxDB, Telegraf, Grafana

REST API for TreatField app Docker compose for TIG and Golang simple app: https://github.com/tochytskyi/treatfield-api/blob/main/docker-compose.yml Gr

Nov 6, 2021

Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Dec 25, 2021

Callable Ajax / http requests inside Golang templates

jaco Callable Ajax / http requests inside Golang templates Examples Examples #1 {{ define "content" }} div id="myTodos"/div script

Dec 5, 2021

Scans files for .jars potentially vulnerable to Log4Shell (CVE-2021-44228) by inspecting the class paths inside the .jar.

log4shelldetect Scans a file or folder recursively for jar files that may be vulnerable to Log4Shell (CVE-2021-44228) by inspecting the class paths in

Dec 15, 2022

Ssh-lxd - A proof of concept for an ssh server that spawns a bash session inside a LXD container

SSH LXD A proof of concept for an ssh server that spawns a bash session inside a

Aug 16, 2022
Related tags
Embed files into a Go executable

statik statik allows you to embed a directory of static files into your Go binary to be later served from an http.FileSystem. Is this a crazy idea? No

Jan 6, 2023
Embed arbitrary resources into a go executable at runtime, after the executable has been built.

ember Ember is a lightweight library and tool for embedding arbitrary resources into a go executable at runtime. The resources don't need to exist at

Nov 9, 2022
Ghostinthepdf - This is a small tool that helps to embed a PostScript file into a PDF

This is a small tool that helps to embed a PostScript file into a PDF in a way that GhostScript will run the PostScript code during the

Dec 20, 2022
Get a binary file directly from the Golang source project.

This project aims to provide a way to get binary file from a Golang project easily. Users don't need to have a Golang environment. Server Usage: docke

Nov 18, 2021
Upgit - Upgit helps you simply upload any file to your Github repository and then get a raw URL for it
Upgit - Upgit helps you simply upload any file to your Github repository and then get a raw URL for it

Upgit - Upgit helps you simply upload any file to your Github repository and then get a raw URL for it

Dec 27, 2022
Rename-pvc can rename PersistentVolumeClaims (PVCs) inside KubernetesRename-pvc can rename PersistentVolumeClaims (PVCs) inside Kubernetes

rename-pvc rename-pvc can rename PersistentVolumeClaims (PVCs) inside Kubernetes. ⚠️ Be sure to create a backup of your data in the PVC before using r

Oct 31, 2022
atwhy is a tool to describe your decisions inside the code where they are actually made and still get a readable documentation.

atwhy What is atwhy atwhy can be used to generate a documentation out of comments in the code. That way you can for example describe all available opt

Oct 30, 2022
OCI transport plugin for apt-get (i.e., apt-get over ghcr.io)

apt-transport-oci: OCI transport plugin for apt-get (i.e., apt-get over ghcr.io) apt-transport-oci is an apt-get plugin to support distributing *.deb

Nov 1, 2022
A library for the MIGP (Might I Get Pwned) protocolA library for the MIGP (Might I Get Pwned) protocol

MIGP library This contains a library for the MIGP (Might I Get Pwned) protocol. MIGP can be used to build privacy-preserving compromised credential ch

Dec 3, 2022
It is a clone of the CRUD operations on Instagram which can create, get, create posts and get the post along with pagination
It is a clone of the CRUD operations on Instagram which can create, get, create posts and get the post along with pagination

Instagram-API-Clone It is a basic version of a RESTful API based on Instagram where we can create user, get the users, create post and get post and ge

Jan 25, 2022