Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

shogo82148/assets-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARCHIVED!

From Go 1.16, Go officially supports embedded files by using the embed package. Please use the embed package instead assets-life. assets-life is no longer maintained.

Build Status

assets-life

assets-life is a very simple embedding asset generator. It generates an embed small in-memory file system that is served from an http.FileSystem.

Usage

Install the command line tool first.

go install github.com/shogo82148/assets-life@latest

The assets-life command generates a package that have embed small in-memory file system.

assets-life /path/to/your/project/public public

You can access the file system by accessing a public variable Root of the generated package.

import (
    "net/http"
    "./public" // TODO: Replace with the absolute import path
)

func main() {
    http.Handle("/", http.FileServer(public.Root))
    http.ListenAndServe(":8080", nil)
}

Visit http://localhost:8080/path/to/file to see your file.

The assets-life command also embed go:generate directive into the generated code, and assets-life itself. It allows you to re-generate the package using go generate.

go generate ./public

The assets-life command is implemented as a Quine (computing) and embedded into the generated package. So the command is no longer needed.

References