DEV Community

deadcheat
deadcheat

Posted on • Updated on

deadcheat/goblet embedding library for assets written in Go

Circumstance

Embedding of assets, is necessary for creating a single binary application in Go.

I used to use github.com/jteeuwen/go-bindata, but go-bindata is somehow removed (url is alive now, but original author is not there).

For that reason, I thought to migrate go-bindata to github.com/jessevdk/go-assets. go-assets is not bad, but it has some problems for me like below -

  • Idempotency, for go-assets, I have to create .go file from asset by using go-assets-builder. but generated .go file is not constant, changed each execution.
  • Seems not to be maintained, there are some PRs that has been left untreated.

So I created my library.

github.com/deadcheat/goblet

How to use

To generate .go file from assets,

  • install
go get -u github.com/deadcheat/goblet/...
Enter fullscreen mode Exit fullscreen mode
  • execute command (plz set $GOPATH/bin to $PATH env before that)
goblet %MYASSETDIR%...
Enter fullscreen mode Exit fullscreen mode
  • Write a code to use them, for example, it can be used for http.FileServe
http.Handle("/static/", http.FileServer(assetsbin.Assets.WithPrefix("/static/")))
log.Println("start server localhost:3000")
if err := http.ListenAndServe(":3000", nil); err != nil {
    log.Fatal(err)
}
Enter fullscreen mode Exit fullscreen mode

If you want to change package name in generated file, use -p flag.

It is not so bad for my use case, but I want it to be more better, please tell me anything what you think about.

Thanks for your reading.

bye.

Top comments (0)