asseter

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Asseter

Go Reference

A Go tool for managing and embedding static assets in your web applications. Asseter helps you copy, compress, and generate embed-backed code for serving static files.

Requirements

  • Go 1.24 or higher

Installation

go get github.com/pudottapommin/asseter/cmd/asseter
# or 
go get -tool github.com/pudottapommin/asseter/cmd/asseter

Usage

Commands
copy - Copy assets to output directory

Copies static assets from a source directory to a distribution directory, with optional font copying from node_modules.

Options:

Flag Default Description
-cwd "" Working directory (where node_modules are located)
-src "src" Source directory for assets
-dist "dist" Distribution directory for assets
-font-dist "files" Fonts distribution directory (rooted from dist)
-exclude - Exclude paths by glob pattern (can be used multiple times)
-font - Font source names to copy from node_modules (can be used multiple times)

Examples:

# Basic copy from 'src' to 'dist'
asseter copy -src src -dist dist

# Copy assets and extract specific fonts from node_modules
asseter copy -src src -dist dist -font inter -font "roboto-mono"

# Copy assets but exclude source map files and typescript files
asseter copy -src src -dist dist -exclude "*.map" -exclude "*.ts"
generate - Generate bindata Go file

Generates Go code for serving static assets by compressing assets into a subfolder and embedding them via Go's //go:embed directive.

Options:

Flag Default Description
-cwd "" Working directory
-src "assets" Directory containing assets to process
-out "bindata.asseter.go" Output Go filename
-pkg "assets" Package name for the generated Go file
-embed-dir "_embed" Subdirectory name for embedded asset files

Examples:

# Generate the asset filesystem from the 'dist' folder
asseter generate -src dist -out internal/assets/bindata.asseter.go -pkg assets

# Generate with a custom embed directory name
asseter generate -src dist -out internal/assets/bindata.asseter.go -pkg assets -embed-dir _embed

Workflow

A typical workflow combines both commands, often orchestrated via a go:generate directive or a build script:

# 1. Gather all assets into a staging 'dist' folder, excluding source maps
asseter copy -src frontend/public -dist dist -exclude "*.map" -font inter

# 2. Generate the compressed, embedded Go filesystem
asseter generate -src dist -out internal/assets/bindata.asseter.go -pkg assets
Using the generated assets in your Go code

Build with the bindata build tag (go build -tags bindata .):

package main

import (
	"net/http"
	"your-project/internal/assets" // Import the generated package
)

func main() {
	mux := http.NewServeMux()
	
	// Serve the embedded static files.
	// The generated assets.Assets implements fs.FS and gracefully handles directories and compression.
	fileServer := http.FileServer(http.FS(assets.Assets))
	mux.Handle("/static/", http.StripPrefix("/static/", fileServer))
	
	http.ListenAndServe(":8080", mux)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetsFsHandler added in v0.3.0

type AssetsFsHandler struct {
	// contains filtered or unexported fields
}

func NewAssetsFsHandler added in v0.3.0

func NewAssetsFsHandler(o AssetsFsOptions) (*AssetsFsHandler, error)

func (*AssetsFsHandler) Run added in v0.3.0

func (h *AssetsFsHandler) Run() error

type AssetsFsOptions added in v0.3.0

type AssetsFsOptions struct {
	Src      string
	Pkg      string
	Out      string
	EmbedDir string
}

type CopyHandler

type CopyHandler struct {
	// contains filtered or unexported fields
}

func NewCopyHandler

func NewCopyHandler(opts CopyOptions) (*CopyHandler, error)

func (*CopyHandler) Run

func (cmd *CopyHandler) Run(ctx context.Context) error

type CopyOptions

type CopyOptions struct {
	Cwd          string
	SrcDir       string
	DistDir      string
	Exclude      FileMatchFlag
	Fonts        FontSourceFontsFlag
	DistFontsDir string
}

type FileMatchFlag

type FileMatchFlag []string

func (*FileMatchFlag) Match

func (e *FileMatchFlag) Match(path string) bool

func (*FileMatchFlag) Set

func (e *FileMatchFlag) Set(value string) error

func (*FileMatchFlag) String

func (e *FileMatchFlag) String() string

type FontSourceFontsFlag

type FontSourceFontsFlag []string

func (*FontSourceFontsFlag) Match

func (e *FontSourceFontsFlag) Match(path string) bool

func (*FontSourceFontsFlag) Set

func (e *FontSourceFontsFlag) Set(value string) error

func (*FontSourceFontsFlag) String

func (e *FontSourceFontsFlag) String() string

Directories

Path Synopsis
cmd
asseter command

Jump to

Keyboard shortcuts

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