Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
/ gogenstatic Public archive

Generate Go (Golang) package, that embeds static/public files and provides HTTP handler to serve them

License

Notifications You must be signed in to change notification settings

mxmCherry/gogenstatic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gogenstatic Build Status

Command gogenstatic generates "static" package, which embeds all the files from public root dir ("--src" param, defaults to "./public") and provides HTTP handler to serve them.

Go get it:

go get -u github.com/mxmCherry/gogenstatic

Usage

  gogenstatic --src=path/to/public/dir --dst=path/to/place/static/package

It is intended to be used with go generate.

Assuming, you have this project structure:

  project/
    public/ # contains some HTML/JS/CSS files
    whatever.go

Then you can add this comment:

  //go generate gogenstatic

to any of your *.go files (like whatever.go) and run:

  go generate ./...

in your project dir, and it'll generate static subpackage, with all the files from ./public/ embedded:

  project/
    public/
    static/ # this will be generated from public/
    whatever.go # contains comment //go generate gogenstatic

Then import generated subpackage and use it's handler:

  import "path/to/your/project/static"
  http.Handle("/mountpoint/", http.StripPrefix("/mountpoint/", static.Handler()))

Or, if you want no runtime hash lookups, you can use handler for a single file:

  http.Handle("/js/file.js", static.HandlerFor("path/to/file.js"))

About

Generate Go (Golang) package, that embeds static/public files and provides HTTP handler to serve them

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages