elazarl / go-bindata-assetfs Goto Github PK
View Code? Open in Web Editor NEWServes embedded files from `jteeuwen/go-bindata` with `net/http`
License: BSD 2-Clause "Simplified" License
Serves embedded files from `jteeuwen/go-bindata` with `net/http`
License: BSD 2-Clause "Simplified" License
I am just getting started with your tool. Great job!
I noticed an error message when I use it for my assets:
$ go-bindata-assetfs -pkg gogrinder -o gogrinder/assetfs.go web/...
Cannot read bindata.go open bindata.go: no such file or directory
creates the asset file but this is section missing:
func assetFS() *assetfs.AssetFS {
for k := range _bintree.Children {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: k}
}
panic("unreachable")
}
I am new to go so sorry for the stupid question. How do I install this as go get is no longer allowed in go version 1.17 and up
Any code described in the "Without running binary tool" section shows is broken by some changes on Go tip/master. The following program can reproduce the issue:
package main
import "github.com/elazarl/go-bindata-assetfs"
func main() {
_ = http.FileServer(&assetfs.AssetFS{})
}
which produces:
# github.com/elazarl/go-bindata-assetfs
../assetfs.go:77: AssetFile.Size is ambiguous
../assetfs.go:77: cannot use f (type *AssetFile) as type os.FileInfo in return argument:
*AssetFile does not implement os.FileInfo (missing Size method)
../assetfs.go:116: AssetDirectory.Size is ambiguous
../assetfs.go:116: cannot use f (type *AssetDirectory) as type os.FileInfo in return argument:
*AssetDirectory does not implement os.FileInfo (missing Size method)
This is because AssetFile
is defined as:
type AssetFile struct {
*bytes.Reader
io.Closer
FakeFile
}
A Go commit in tip (golang/go@c264c87) added a Size
method to *bytes.Reader
, and since FakeFile
also has a Size
method -- it's ambiguous and thus breaks.
this looks really nice.
i am thinking of a slightly different applicatin of this.
I think i can use this for packaging my own server deployment package too. Like when you need a stupid c lib on the server or client. i can pack it in, and then install it from a nice single deployed app.
the .sh bash install script can be embedded, but i expect a golang server on the server will need to call it, due to security issues.
does anyone else know a different way of approaching this ? Or maybe your interested in extending this project to do it, or make another project that uses this to do it.
Tags and versions aid in packaging for things like .deb files, and for anyone wanting to use Glide and other version based package managers to version their dependencies. It would also help ensure that if you make a breaking change, we don't pull it down until we are ready.
Hello
I'm stuck with an issue regarding go-bindata and unrolled/render. I uploaded a sample code for reproduction: https://github.com/hachi8833/myapp
I added a route for assets as suggested in unrolled/render#44, and looked fine at first. But actually the loaded assets (css, js) from go-bindata binary are all empty (except template) while HTTP status are successful with 200.
Note that template files under template/*.tmpl are loaded with github.com/unrolled/render.
I'm wondering if I misunderstand or overlook something and I'd be glad if you point out what is wrong with my code.
Best regards,
I wonder if you would consider a change to AssetFS to protect others from a problem I had, and took quite a while for me to find the root cause?
I have a project that used your older API (without the AssetInfo field).
http.Handle("/",
http.FileServer(
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir}))
My project still compiled fine with the newer versions of AssetFS code despite what is now a missing initialiser, but hits a null pointer error at run time at line 148 in assetfs.go with this:
if info, err := fs.AssetInfo(name); err == nil {
All fine now I updated my call of course, but shame to require others who hit the same problem to dig into AssetFS source to work out what's happening.
Pete
Has anyone tested it with CDN yet?
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
On May 9th there was a PR that adds a fallback for Single page Applications. Right now the code is only in master, can you make a tag/release v1.0.1 so go.mod
can reference directly to it and not master?
thanks!
A line from a PR that was merged yesterday is causing generated files to error because os
is being imported twice, once by the addition of this line and once by the import that go_bindata
generates.
I don't believe the os
addition is necessary for any set of underlying options sent to go_bindata
. It looks like all of the possible import headers it could write out all include os
:
It would be neat to check an HTTP request for Accept-Encoding: gzip
to return assets with a Content-Encoding: gzip
header and the compressed asset body.
Is there already a way to do this that I've missed?
The fileserver implementation returns http 200 regardless if the file exists or not or if there is any other error reading it.
assetFS is not exportable. so i do :
go-bindata-assetfs -pkg res resources/..
then in generated bindata_assetfs.go i changing assetFS to AssetFS and using it like
import {...
"bindata_assetfs"
}
http.Handle("/resources", http.FileServer(res.AssetFS()))
theres no function called AssetFs
in the produced code
Hey it would be great if the import order followed the go style guide. The side effect of this is that projects that lint fail because of the generated code.
The imports should look like:
package agent
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/elazarl/go-bindata-assetfs"
)
Can I write or remove and add file in the AssetFS pragmatically?
/bindata_assetfs.go:9527: undefined: _bintree in _bintree.Children
./bindata_assetfs.go:9528: undefined: AssetDir
./bindata_assetfs.go:9528: undefined: AssetInfo
I fail to see how this would work because it seems the constant bindatafile
[0] is never created so the call is doomed to fail isn't it ? Is this supposed to be created in a different taks?
``go-bindata-assetfs -o bin.go dist/...
Cannot read bindata.go open bindata.go: no such file or directory``
[0] https://github.com/elazarl/go-bindata-assetfs/blob/master/go-bindata-assetfs/main.go#L44
The Prefix
property (and underlying code) does not behave as expected.
If one have data
directory with two files, for example, app.html
and index.html
, overall Prefix
property of assetFS
becomes equal to the path of one of the files in the dir (for example, Prefix = data/app.html
).
The Open()
call (as seen from sources) just prepends Prefix
field to the requested file name, which, considering the above, leads to unavailability of all packed files -- request to data/index.html
is translated to data/app.html/data/index.html
which is not quite correct.
If one is specifying the prefix explicitly with --prefix
key the software acts exactly the same.
A dirty resolution to the issue is to completely omit Prefix
field, then it works like a charm.
go-bindata-assetfs -pkg=bootstrap css fonts js
Only the css folder is returned.
func assetFS() *assetfs.AssetFS {
for k := range _bintree.Children {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: k}
}
panic("unreachable")
}
Among my assets I have a 404.html. I am finding it troublesome to get net/http to host that as the final 404. Since I am hosting the assetfs at "/", I can't figure out how to make it work.
What if I could define something like this:
http.Handle("/", http.FileServer( &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "data", DefaultDoc:"404.html"}))
I can submit a pull request if you like. What do you think?
The problem that got me there: FakeFile's Modtime is the binary's startup time, which breaks all caching on restart and with multiple instances.
What's the reason for this? If you're ok with that, I'd make a pull request in the next days changing it to use AssetInfo().
Have a good one! :)
The merge of #16 broke my build.
Error message :
flag provided but not defined: -prefix
From now we can't use go-bindata
arguments ?
when I want use go-bindata in windows system,some error happens.D:\go\src\git.bwae.org\portal\cluster-admin>go-bindata-assetfs web\ui\... bindata: open web\ui\...: Access is denied. Error: go-bindata: exit status 1
linux is ok.
./go-binddata-assetfs -o go-bindata-assetfs/blah.go go-bindata-assetfs
fails as the expected file is hardcoded to binddata.go
I needed to use this library to embed my static files but when applying golint it fails due to functions containing underscores inside names etc.
It is a little boring replacing all those functions names for my static file with CameCase style.
I finished changing your convert.go, safeFunctionName function, replacing "_" with "". to remove _ from names.
Thanks.
Problem:
I want to declare multiple files when using the go-bindata-assetfs
cmd:
$ go-bindata-assetfs dist/... public/...
OR I want to only specify the dist
directory:
$ go-bindata-assetfs dist/...
But because the dist
directory has a public
directory sibling, the assetFS()
will randomly pick either the dist
or public
directory to generate from.
Issue:
The call to assetFS()
will randomly pass back only the first item in the _bintree.Children
slices, which means that if I pass a top level directory with multiple children directories assetFS()
will not return the desired results.
Requested changes:
I want to be able to define each static path to serve manually, either multiple of a single child directory. This example demonstrates serving 2 static directories but even if i just want to serve a single directory assetFS()
will not work if there are more than 1 directories present:
func main() {
r := mux.NewRouter() // Example uses "github.com/gorilla/mux"
// Here we want to serve static content from 2 directories
r.PathPrefix("/dist").Handler(http.StripPrefix("/dist", http.FileServer(AssetDIR("dist"))))
r.PathPrefix("/public").Handler(http.StripPrefix("/public", http.FileServer(AssetDIR("public"))))
// rest of server code...
server := &http.Server{ Addr: ":7777", Handler: r, }
server.ListenAndServe()
}
I'm getting the following error in the generated file bindata_assetfs.go
:
undefined: AssetInfo
This happens in this generated function:
func assetFS() *assetfs.AssetFS {
for k := range _bintree.Children {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: k}
}
panic("unreachable")
}
I get a runtime error when using AssetInfo(name) on line (https://github.com/elazarl/go-bindata-assetfs/blob/master/assetfs.go#L148). I can't seem to figure out why though. The file is there.. any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.