A zero dependency asset embedder for Go

Overview

Mewn

A zero dependency asset embedder for Go.

Go Report Card GoDoc CodeFactor Generic badge Generic badge Generic badge

About

Mewn is perhaps the easiest way to embed assets in a Go program. Here is an example:

package main

import (
	"fmt"

	"github.com/leaanthony/mewn"
)

func main() {
	myTest := mewn.String("./assets/hello.txt")
	fmt.Println(myTest)
}

If compiled with go build, this example will read hello.txt from disk. If compiled with mewn build, it will embed the assets into the resultant binary.

Installation

go get github.com/leaanthony/mewn/cmd/mewn

Usage

Import mewn at the top of your file github.com/leaanthony/mewn then use the simple API to load assets:

  • String(filename) (string) - loads the file and returns it as a string
  • Bytes(filename) ([]byte) - loads the file and returns it as a byte slice
  • MustString(filename) (string) - loads the file and returns it as a string. Any error is considered fatal
  • MustBytes(filename) ([]byte) - loads the file and returns it as a byte slice. Any error is considered fatal

Groups

To bundle a whole directory, simply declare a group like this:

myGroup := mewn.Group("./path/to/dir")

From this point you can use the same methods above, but on the group:

myAsset := myGroup.String("file.txt")

Groups also have the following method:

  • Entries() []string - Returns a slice of filenames in the Group

Mewn cli command

The mewn command does 3 things:

  • If you run mewn, it will recursively look for mewn.* calls in your .go files. It will then generate intermeriary go files with assets embedded. It does not compile them into a final binary.
  • mewn build will do the above, but compile all the source, then delete the intermediary files. This makes things a bit cleaner.
  • mewn pack will do the same as wails build, but will compile with the go flags -ldflags "-w -s" to compress the final binary even more.

For the build and pack subcommands, any other cli parameters will be passed on to go build.

Caveats

This project was built for simple embedding of assets and as such, there are a number of things to consider when choosing whether or not to use it.

  • Mewn just deals with bytes. It's up to you to convert that to something you need. One exception: String. Just because it's super likely you'll need it.
  • When using the top-level methods, EG: mewn.String(), it uses a default group called ".". Creating your own group called "." shouldn't do anything, but I'm not going to guarrantee it. You've been warned 😉
  • Paths to assets need to be unique (within a Group). If you try to pack 2 files with the same relative path with the same group (or default group), it isn't going to work.
  • Once this project reaches 1.0, it is extremely unlikely that any new features will be added in the future. This is by choice, not necessity. I want this project to be extremely stable so if you choose to use it today, it should work exactly the same in 3 years time. If it doesn't currently do what you want, you are probably looking for a different project. However, if you have a phenomenally good idea, feel free to open an issue.
  • The project works by parsing the AST tree of your code. It works when you use the form mydata := mewn.String('./myfile.txt') to import your data (IE string literal, not variable). It may not (yet) work for similar code. Very happy to receive bug fixes if it doesn't.

Bug reports are very welcome! Almost as much as PRs to fix them!

What does 'Mewn' mean?

Mewn (MEH-OON as fast as you can say it, not meee-oon) is the Welsh word for "in".

Why go for a crazy Welsh name?

Well, it stands out as a project name (practically zero name clashes) and is one of the oldest and coolest languages in Europe (which I'm lucky enough to speak). JRR Tolkien was obsessed with Welsh. So much so, he based the Middle Earth Elvish language "Sindarin" on it and there's strong evidence he based LOTR on Welsh mythology. It's also associated with Red Dragons, weirdly loved by the Bundesliga football team FC Schalke and it's on Duolingo, so why not give it a go 😉 .

Inspiration

Heavy inspiration was drawn from packr by the awesome Mark Bates. The scope of what I needed was far narrower than the packr project, thus Mewn was born. If Mewn doesn't fulfil your needs, it's likely that packr will.

You might also like...
MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

MNA - stands for mobile number assignment - a small zero external dependency golang library that is used to identify mobile number assignment in tanzania

 CDK - Zero Dependency Container Penetration Toolkit
CDK - Zero Dependency Container Penetration Toolkit

CDK is an open-sourced container penetration toolkit, offering stable exploitation in different slimmed containers without any OS dependency. It comes with penetration tools and many powerful PoCs/EXPs helps you to escape container and takeover K8s cluster easily.

alog is a dependency free, zero/minimum memory allocation JSON logger with extensions
alog is a dependency free, zero/minimum memory allocation JSON logger with extensions

Alog (c) 2020-2021 Gon Y Yi. https://gonyyi.com. MIT License Version 1.0.0 Intro Alog was built with a very simple goal in mind: Support Tagging (and

Web-based, zero-config, dependency-free database schema change and version control tool for teams
Web-based, zero-config, dependency-free database schema change and version control tool for teams

Live Demo • Install • Help • Development • Design Doc Bytebase is a web-based, zero-config, dependency-free database schema change and version control

Scheduler - Scheduler package is a zero-dependency scheduling library for Go

Scheduler Scheduler package is a zero-dependency scheduling library for Go Insta

Golang flags parser with zero dependency

flags Golang flags parser with zero dependency. Usage See simple.go for basic usage. Concept flags gives a simple way to get flag's value from argumen

Goworkers - Zero dependency Golang worker pool

Golang Worker Pool Zero dependency golang goroutines pool library. It is useful

wazero: the zero dependency WebAssembly runtime for Go developers

wazero: the zero dependency WebAssembly runtime for Go developers WebAssembly is a way to safely run code compiled in other languages. Runtimes execut

A zero-dependency cache library for storing data in memory with generics.

Memory Cache A zero-dependency cache library for storing data in memory with generics. Requirements Golang 1.18+ Installation go get -u github.com/rod

A Simple and Clear CLI library. Dependency free.
A Simple and Clear CLI library. Dependency free.

A Simple and Clear CLI library. Dependency free. Features Nested Subcommands Uses the standard library flag package Auto-generated help Custom banners

Dependency-free replacement for GNU parallel, perfect fit for usage in an initramfs.

coshell v0.2.5 A no-frills dependency-free replacement for GNU parallel, perfect for initramfs usage. Licensed under GNU/GPL v2. How it works An sh -c

A Go dependency graph visualization tool
A Go dependency graph visualization tool

godepgraph godepgraph is a program for generating a dependency graph of Go packages. Install go get github.com/kisielk/godepgraph Use For basic usage

hiboot is a high performance web and cli application framework with dependency injection support

Hiboot - web/cli application framework About Hiboot is a cloud native web and cli application framework written in Go. Hiboot is not trying to reinven

An additive dependency injection container for Golang.

Alice Alice is an additive dependency injection container for Golang. Philosophy Design philosophy behind Alice: The application components should not

🛠 A full-featured dependency injection container for go programming language.

DI Dependency injection for Go programming language. Tutorial | Examples | Advanced features Dependency injection is one form of the broader technique

A reflection based dependency injection toolkit for Go.

⚒️ dig A reflection based dependency injection toolkit for Go. Good for: Powering an application framework, e.g. Fx. Resolving the object graph during

Go Dependency Injection Framework

Dingo Dependency injection for go Hello Dingo Dingo works very very similiar to Guice Basically one binds implementations/factories to interfaces, whi

A dependency injection based application framework for Go.

🦄 Fx An application framework for Go that: Makes dependency injection easy. Eliminates the need for global state and func init(). Installation We rec

Simple Dependency Injection Container
Simple Dependency Injection Container

🪣 gocontainer gocontainer - Dependency Injection Container 📖 ABOUT Contributors: Rafał Lorenz Want to contribute ? Feel free to send pull requests!

Comments
  • Windows environment escape bug in intermediary generated files

    Windows environment escape bug in intermediary generated files

    When mewn generates the intermediary files the filepaths are not escaping.

    Desired results (With double bars):

    func init() {
    	mewn.AddAsset("../../ui/html", "F:\\DOCUMENTS\\GO_PATH\\   ( continues ...)
    

    Current results (With only a bar):

    func init() {
    	mewn.AddAsset("../../ui/html", "F:\DOCUMENTS\GO_PATH\   ( continues ...)
    

    I can't build with the current version. Go shows the errors: cmd\web\main-mewn.go:8:38: unknown escape sequence cmd\web\main-mewn.go:8:79: non-hex character in escape sequence: i

    Thank you in Advance!

    opened by odhs 7
Releases(v0.10.5)
Owner
Lea Anthony
Lea Anthony
ddlcpad, *Doki Doki Literature Club Plus Asset Decrypter*, is a tool to decrypt the encrypted asset file on the Doki Doki Literature Club Plus. Writing in golang.

ddlcpad 简体中文 What is this ddlcpad is short of Doki Doki Literature Club Plus Asset Decrypter You can decrypt the *.cy file from Doki Doki Literature C

Aimer Neige 19 Jun 30, 2022
A simple file embedder for Go

esc esc embeds files into go programs and provides http.FileSystem interfaces to them. It adds all named files or files recursively under named direct

Matt Jibson 624 Sep 15, 2022
A Go (golang) Custom Flutter Engine Embedder for desktop

Go Flutter desktop embedder ⚠️ Warning: this project has been moved to its own organization. Please take a look at its new location: github.com/go-flu

Pierre Champion | Drakirus 96 Jul 23, 2022
🌀 Dismap - Asset discovery and identification tool

?? Dismap - Asset discovery and identification tool [English readme Click Me] Dismap 定位是一个资产发现和识别工具;其特色功能在于快速识别 Web 指纹信息,定位资产类型。辅助红队快速定位目标资产信息,辅助蓝队发现疑

之乎者也 1.2k Sep 18, 2022
staticfiles is an asset manager for a web applications written in Go.

Overview staticfiles is an asset manager for a web applications written in Go. It collects asset files (CSS, JS, images, etc.) from a different locati

null 10 Mar 29, 2022
Asset storage and on-the-fly image resize

air - Asset & Image Resize Asset storage and on-the-fly image resize powered by libvips. Uploading an asset $ http -f POST http://127.0.0.1:1323/uploa

Alexandre Ferland 0 Feb 5, 2022
IT Asset Fleet Remote Management and Monitoring (RMM) platform

ratd Remote Access Toolkit Daemon IT Asset Remote Management and Monitoring (RMM) platform How to use: You can't, just yet. Release Plan Release 0 Cre

null 11 Sep 2, 2022
Simple, zero-dependency scheduling library for Go

go-quartz Simple, zero-dependency scheduling library for Go. About Inspired by the Quartz Java scheduler. Library building blocks Job interface. Any t

Eugene R. 947 Sep 24, 2022
A powerful zero-dependency json logger.

ZKits Logger Library About This package is a library of ZKits project. This is a zero-dependency standard JSON log library that supports structured JS

Qingshan Luo 20 Sep 22, 2022
Machine is a zero dependency library for highly concurrent Go applications.

Machine is a zero dependency library for highly concurrent Go applications. It is inspired by errgroup.Group with extra bells & whistles

Coleman Word 355 Sep 3, 2022