Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: be able to use both go-bindata and go-bindata-assetfs at the same time #20

Closed
timhughes opened this issue Jul 5, 2015 · 7 comments

Comments

@timhughes
Copy link

I would like to use go-bindata-assetfs for serving static assets such as javascript and css but then use go-bindata for my templates but when I do I get naming clashes. I also do not want to serve my templates using http.FileSystem . I think this use case will come up a lot when building tiny web apps.

go-bindata-assetfs -o static_bindata.go static/... 
go-bindata -o template_bindata.go templates/...
go build
Cannot read bindata.go open bindata.go: no such file or directory
# git.timhughes.org/timhughes/githook
./template_bindata.go:20: bindataRead redeclared in this block
    previous declaration at ./static_bindata.go:19
./template_bindata.go:40: asset redeclared in this block
    previous declaration at ./static_bindata.go:39
./template_bindata.go:45: bindataFileInfo redeclared in this block
    previous declaration at ./static_bindata.go:44
./template_bindata.go:52: bindataFileInfo.Name redeclared in this block
    previous declaration at ./static_bindata.go:51
./template_bindata.go:55: bindataFileInfo.Size redeclared in this block
    previous declaration at ./static_bindata.go:54
./template_bindata.go:58: bindataFileInfo.Mode redeclared in this block
    previous declaration at ./static_bindata.go:57
./template_bindata.go:61: bindataFileInfo.ModTime redeclared in this block
    previous declaration at ./static_bindata.go:60
./template_bindata.go:64: bindataFileInfo.IsDir redeclared in this block
    previous declaration at ./static_bindata.go:63
./template_bindata.go:67: bindataFileInfo.Sys redeclared in this block
    previous declaration at ./static_bindata.go:66
./template_bindata.go:94: Asset redeclared in this block
    previous declaration at ./static_bindata.go:73
./template_bindata.go:94: too many errors
@slimsag
Copy link

slimsag commented Jul 5, 2015

You can already, but thet will have to be in separate (sub) packages which
is nicer anyway IMO)
On Jul 5, 2015 2:22 PM, "Tim Hughes" notifications@github.com wrote:

I would like to use go-bindata-assetfs for serving static assets such as
javascript and css but then use go-bindata for my templates but when I do
I get naming clashes. I also do not want to serve my templates using
http.FileSystem . I think this use case will come up a lot when building
tiny web apps.

go-bindata-assetfs -o static_bindata.go static/...
go-bindata -o template_bindata.go templates/...
go build

Cannot read bindata.go open bindata.go: no such file or directory

git.timhughes.org/timhughes/githook

./template_bindata.go:20: bindataRead redeclared in this block
previous declaration at ./static_bindata.go:19
./template_bindata.go:40: asset redeclared in this block
previous declaration at ./static_bindata.go:39
./template_bindata.go:45: bindataFileInfo redeclared in this block
previous declaration at ./static_bindata.go:44
./template_bindata.go:52: bindataFileInfo.Name redeclared in this block
previous declaration at ./static_bindata.go:51
./template_bindata.go:55: bindataFileInfo.Size redeclared in this block
previous declaration at ./static_bindata.go:54
./template_bindata.go:58: bindataFileInfo.Mode redeclared in this block
previous declaration at ./static_bindata.go:57
./template_bindata.go:61: bindataFileInfo.ModTime redeclared in this block
previous declaration at ./static_bindata.go:60
./template_bindata.go:64: bindataFileInfo.IsDir redeclared in this block
previous declaration at ./static_bindata.go:63
./template_bindata.go:67: bindataFileInfo.Sys redeclared in this block
previous declaration at ./static_bindata.go:66
./template_bindata.go:94: Asset redeclared in this block
previous declaration at ./static_bindata.go:73
./template_bindata.go:94: too many errors


Reply to this email directly or view it on GitHub
#20.

@markwallsgrove
Copy link
Contributor

@timhughes when using go-bindata-assetfs and/or go-bindata use the -pkg flag to achieve what @slimsag suggested.

go-bindata-assetfs -o static_bindata.go -pkg static static/... 
go-bindata -o template_bindata.go -pkg templates templates/...
go build

@xiaods
Copy link

xiaods commented May 15, 2016

cool

@jbowens
Copy link

jbowens commented Jun 26, 2016

Why does go-bindata-assetfs require it's own command? Can you not implement http.FIleSystem through the go-bindata table of contents?

@elazarl
Copy link
Owner

elazarl commented Jun 27, 2016

@jbowens this is to create the actual go files containing the data.

@jbowens
Copy link

jbowens commented Jun 27, 2016

@elazarl Right. My question is how it differs from go-bindata. AFAICT, go-bindata-assetfs doesn't generate any additional data beyond what go-bindata generates.

It seems to me you could use go-bindata to generate the the Go files with the data as normal, and then go-bindata-assetfs can expose a function like:

type BindataPkg struct {
    Asset     func(string) ([]byte, error)
    AssetInfo func(string) (os.FileInfo, error)
    AssetDir  func(name string) ([]string, error)
}

func FileSystem(bindata BindataPkg) http.FileSystem {
    // ...
}

Then instead of having to use a separate command for go-bindata-assetfs, users can generate Go using go-bindata and within their application call:

fs := assetfs.FileSystem(BindataPkg{
    Asset:     myassetspkg.Asset,
    AssetInfo: myassetspkg.AssetInfo,
    AssetDir:  myassetspkg.AssetDir,
})
mux.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(fs)))

Why does go-bindata-assetfs need code generation beyond what go-bindata already provides?

@jbowens
Copy link

jbowens commented Jun 27, 2016

Ah, sorry, I see. That's literally what AssetFS is. The code generation tool is just intended for convenience?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants