go-bindata / go-bindata Goto Github PK
View Code? Open in Web Editor NEWTurn data file into go code.
License: Other
Turn data file into go code.
License: Other
would be nice to have binary releases, as go-bindata is used so much in CI etc, and its easier to pull a binary.
It would be great if go-bindata should be deployed also as .deb
and .rpm
package for every release. Currently I package the go-bindata by myself and would give up it in your hands as developer.
When using the -prefix
flag then the specified prefix is removed from the _bindata
, however, there's a comment at the very top of the auto generated file listing all resources that are found and they still do contain the prefix
//Package main generated by go-bindata.// sources:
...
would be good to remove the prefix from the files listed in the comment as well
Simple test:
bintest
dir directory with binary filesgo-bindata -pkg bintestout -o ./bintestout/files.go ./bintest/*
syntax error: unexpected {, expecting expression
My go version:
go version go1.11.4 linux/amd64
go-bindata version:
go-bindata --version
go-bindata 3.1.0 (Go runtime go1.11.4).
Copyright (c) 2010-2013, Jim Teeuwen.
I'm seeing these linter warnings on generated code (see screenshots):
error strings should not be capitalized (ST1005)
file mode '420' evaluates to 0644; did you mean '0420'? (SA9002)
Not a big deal, but I'd like to keep my workspace clean of warnings. go-staticcheck
seems especially opinionated about how to do this, and wants to put this on the responsibility of library authors: dominikh/go-tools#429 (comment)
There are a few options I can see:
//lint:file-ignore
(or a rule-specific ignore) to silence the warningsWhat do you think? I'm happy to put up a PR once there is a decision
when i use Asset
function, i need to type the whole path and filename, and it's very easy to go wrong and not user-friendly, but when i type a "/" first, the IDE recognize that i am trying to access a file from root, so it lists the tree(most IDE or editor has this feature), i just need to select the file, no typing at all.
without "/" prefix, IDE resolve the path with current file's directory, but my assets are under the project root directory.
so if go-bindata
treats /path/to/asset
as path/to/asset
, it will be pretty nice.
Hi, is it possible to embed binary (e.g. an .exe for windows) and execute it in memory (without writing the file to disk first) ?
Currently is impossible to read the source files from the file system during the development.
Put static assets for a web site to the following directory structure in the project root:
assets/
js/
css/
Generate assets.go
for the context of the assets
directory:
$ go-bindata -debug -fs -o assets.go -prefix assets assets/...
Running the project fails (and so does a build):
$ go build main.go assets.go
# command-line-arguments
assets.go:120:10: undefined: bindataFileInfo
Running or building the project with assets.go
generated with the -dev
switch fails with the same error (you have to define rootDir
). Running or building the project with assets.go
generated without the -debug
switch works well.
The workaround is to copy the declaration of bindataFileInfo
and its methods from the generated output without the debug
switch to the development project.
centos 7
CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ go build main.go
arm run
root@AM335x:mnt# ./main
Segmentation fault
Go-bindata Specifies whether arm is supported?
go run github.com/go-bindata/go-bindata/go-bindata -debug -fs -nomemcopy -prefix ../static ../static
produces a bindata.go
file with partial code generation; the bindataFileInfo
struct used by newDirFileInfo
is undefined and does not compile.
// newDirFileInfo return default dir file info
func newDirFileInfo(name string) os.FileInfo {
return &bindataFileInfo{
name: name,
size: 0,
mode: os.FileMode(2147484068), // equal os.FileMode(0644)|os.ModeDir
modTime: time.Time{}}
}
When running the tool gosec, it throws an error on the generated code, for the G110 rule - Potential DoS vulnerability via decompression bomb.
G110 (CWE-409): Potential DoS vulnerability via decompression bomb (Confidence: MEDIUM, Severity: MEDIUM)
io.Copy(&buf, gz)
It is advised to use io.CopyN when doing a decompression. Related issue - securego/gosec#433
Hi, the command line go get -u github.com/go-bindata/go-bindata/...
threw no error but when I wanted to use go-bindata data/
I got zsh: command not found: go-bindata
so I am not sure whether go-bindata has been installed and when it was then probably not added into PATH
yet.
Hi guys, why I got this error ya?
I have this command run in makefile
ifndef BINDATA
@go get -u github.com/kevinburke/go-bindata
@go get -u github.com/kevinburke/go-bindata/...
endif
@echo ${VERSION}-b${BITBUCKET_COMMIT} > resources/VERSION
@go-bindata -pkg utils -o lib/utils/asset.go resources/config/... resources/sql/... resources/VERSION resources/locales/... resources/assets/... resources/credentials/...
and I am very confident that sql file for that version is already in "resources/sql/" folder
I found that there seems to be a problem with your program. If you scan the same warehouse multiple times, it is very likely that different licenses will be returned, and some results seem unreliable. I have checked the warehouse and it shows that it is an MIT license, but The result after scanning turned out to be json.
I tried using the -fs
flag on this project by following the instructions at the bottom of the readme but the http routes are all 404 Not Found.
Here's a repo that reproduces the pathology, including go tests:
https://github.com/clstrco/gbdfail
I had to split the logic up for registering the routes from main so it could be used in the tests; that's found here. The test code can be found here.
The project pins go-bindata
at latest release found by the go tool (see the go.mod file)
Please let me know if I can provide other info.
go-bindata -pkg frontend -o libs/frontend/data.go -nometadata ../frontend/...
directory structure looks liek this:
the generated data.go file does not have the assets.
However, if I add some file under the parent directory frontend
, that file is added.
Looks like the documented ...
is ignored
https://gobindata.github.io site does not exist not does the repo
It would be nice if this library played nice with go mod. Currently, when you run go get "github.com/go-bindata/go-bindata" you get the following in your go.mod file "github.com/go-bindata/go-bindata v3.1.2+incompatible" and the library is unavailable to use.
If you're not careful, you can include hidden files in your bundle, such as "path/to/.myfile.js.swp" (e.g. a vim swap file).
When such a file is included, an exported name is generated: MyfileJsSwp
.
Also, it's easy for this to go unnoticed, unless you're opening up the generated code.
I think these would help:
go-bindata -o=path/asset/asset.go -pkg=asset ./dist/...
func main() {
fs := &assetfs.AssetFS{
Asset: asset.Asset,
AssetDir: asset.AssetDir,
AssetInfo: asset.AssetInfo,
Prefix: "dist",
}
router.StaticFS("/dist", fs)
router.GET("/static/*url", func(c *gin.Context) {
pre, exist := c.Params.Get("url")
if !exist {
return
}
c.Redirect(http.StatusMovedPermanently, "/dist/static"+pre)
})
router.GET("/favicon.ico", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/dist/favicon.ico")
})
}
When running go get -u github.com/go-bindata/go-bindata/...
or go install -a -v github.com/go-bindata/go-bindata/...@latest
(as suggested by another user), and then try to run go-bindata
, I get: "'go-bindata' is not recognized as an internal or external command, operable program or batch file."
Strange thing is that I've had it work once but I can't remember what I did
Operating system: Windows 10 (but I experience this problem on Linux too)
Go version: go1.19.4 windows/amd64
When "hotelId=4" is added, the data cannot be "curl" out.
repos: https://github.com/harlow/go-micro-services
data format:
[
{
"hotelId": "1",
"code": "RACK",
"inDate": "2015-04-09",
"outDate": "2015-04-10",
"roomType": {
"bookableRate": 109.00,
"code": "KNG",
"description": "King sized bed",
"totalRate": 109.00,
"totalRateInclusive": 123.17
}
},
{
"hotelId": "2",
"code": "RACK",
"inDate": "2015-04-09",
"outDate": "2015-04-10",
"roomType": {
"bookableRate": 139.00,
"code": "QN",
"description": "Queen sized bed",
"totalRate": 139.00,
"totalRateInclusive": 153.09
}
},
{
"hotelId": "3",
"code": "RACK",
"inDate": "2015-04-09",
"outDate": "2015-04-10",
"roomType": {
"bookableRate": 109.00,
"code": "KNG",
"description": "King sized bed",
"totalRate": 109.00,
"totalRateInclusive": 123.17
}
},
{
"hotelId": "4",
"code": "RACK",
"inDate": "2015-04-09",
"outDate": "2015-04-10",
"roomType": {
"bookableRate": 139.00,
"code": "QN",
"description": "Queen sized bed",
"totalRate": 139.00,
"totalRateInclusive": 153.09
}
}
]
Need to follow the guidelines outlined here: https://golang.org/s/generatedcode
That means that the comment must begin with // Code generated
and must end with DO NOT EDIT.
I am referencing this recent commit:
0cb4714#diff-76b9265a0c3cccec7fb95e6bde2f273aR53
I'll also reference how golint recognizes these special comments: golang/lint@a5f4a24
gzip has diffrent compression level, go-bindata can support this?
https://github.com/golang/go/blob/f1deee0e8c5f31d86301fe3ec6554a93da0d7e42/src/compress/gzip/gzip.go#L19-L23
https://github.com/golang/go/blob/f1deee0e8c5f31d86301fe3ec6554a93da0d7e42/src/compress/gzip/gzip.go#L60
NewWriter() --> NewWriterLevel(), and add a para to go-bindata.
Line 49 in b139d7d
Line 342 in ee3c241
Line 369 in ee3c241
go get -u github.com/go-bindata/go-bindata/...
go get: installing executables with 'go get' in module mode is deprecated.
To adjust and download dependencies of the current module, use 'go get -d'.
To install using requirements of the current module, use 'go install'.
To install ignoring the current module, use 'go install' with a version,
like 'go install example.com/cmd@latest'.
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
Is anyone going to maintain this code this time around?
I see simple documentation PRs that have been around for over a month, which makes me think this project is going to continue to rot.
I use this utility frequently and I'd be happy to help maintain it.
I'm packing a bunch of static web assets into a single static.go
file for compilation:
go:generate go-bindata -fs -pkg webui -o static.go static/...
I check in this generated file along with any modified files in static/... I check in this file because other packages depend on this asset API downstream. Every time I run my test suite, go-bindata modifies static.go with unnecessary changes:
--- a/webui/static.go
+++ b/webui/static.go
@@ -237,7 +237,7 @@ func staticApplicationCss() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "static/application.css", size: 41308, mode: os.FileMode(420), modTime: time.Unix(1581459437, 0)}
+ info := bindataFileInfo{name: "static/application.css", size: 41308, mode: os.FileMode(420), modTime: time.Unix(1584552628, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -317,7 +317,7 @@ func staticDashboardJs() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "static/dashboard.js", size: 238444, mode: os.FileMode(420), modTime: time.Unix(1571355237, 0)}
+ info := bindataFileInfo{name: "static/dashboard.js", size: 238444, mode: os.FileMode(420), modTime: time.Unix(1584552628, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -557,7 +557,7 @@ func staticLocalesEnYml() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "static/locales/en.yml", size: 2028, mode: os.FileMode(420), modTime: time.Unix(1562361650, 0)}
+ info := bindataFileInfo{name: "static/locales/en.yml", size: 2028, mode: os.FileMode(420), modTime: time.Unix(1584552628, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
(note that modTime is the only change for these three lines)
The contents of the files have not changed. Is there some way to use a contents hash or some other logic to prevent unnecessary changes to static.go?
The error strings in a generated bindata.go
file start with a capital letter. This is contrary to community practice as described at https://github.com/golang/go/wiki/CodeReviewComments#error-strings
For example, a generated Asset()
function contains
return nil, fmt.Errorf("Asset %s not found", name)
By convention that should be
return nil, fmt.Errorf("asset %s not found", name)
Is the project team open to a pull request that updates error strings to follow the community practice?
hi,
if i do go-bindata -debug -fs -prefix "build/" build/...
and then compile the resulting file I get this error.
./bindata.go:138:10: undefined: bindataFileInfo
Obviously, the difference is
// newDirFileInfo return default dir file info
func newDirFileInfo(name string) os.FileInfo {
return &bindataFileInfo{
name: name,
size: 0,
mode: os.FileMode(2147484068), // equal os.FileMode(0644)|os.ModeDir
modTime: time.Time{}}
}
does not have
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
// Name return file name
func (fi bindataFileInfo) Name() string {
return fi.name
}
// Size return file size
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
// Mode return file mode
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
// Mode return file modify time
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
// IsDir return file whether a directory
func (fi bindataFileInfo) IsDir() bool {
return fi.mode&os.ModeDir != 0
}
// Sys return file is sys mode
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
generated with -debug
switch.
go-bindata -version
go-bindata 3.1.3 (Go runtime go1.12.5).
Copyright (c) 2010-2013, Jim Teeuwen.
thanks!
I have a bindata.go
file - what is the easiest way to "unpack" all the assets back into regular files on disk?
Hello,
currently I need for lot's of golang projects go-bindata. The most time, I compile durning the ci pipeline the projects inside a official go container image.
Maybe it's possible to integrate inside the ci pipeline of this projects steps to publish a official container image with go-bindata.
So I can change my ci-pipeline to this example:
# BINDATA
# ===========================================
FROM gobindata/gobindata:latest AS bindata
ADD ./workspace/project/test /workspace
RUN gobindata -pkg main -o bindata_test.go /workspace
# BUILD
# ===========================================
FROM golang:1.13.1 AS build
COPY --from=bindata /workspace/bindata_test.go /workspace/bindata_test.go
RUN go build CGO_ENABLED=0 /workspace/main.go -o dummy
# TARGET CONTAINER
# ===========================================
FROM busybox:latest
COPY --from=build /workspace/dummy /usr/bin/dummy
ENTRYPOINT [ "/usr/bin/dummy " ]
why reset versions, i.e create only 1.0.0 tag?
❯ du -sh archive_bindata/archive_data.go
4.5G archive_bindata/archive_data.go
❯ du -sh archive_bindata/test_archive.tar.xz
1.6G test_archive.tar.xz
Used the following to generate archive_bindata/archive_data.go
:
❯ go-bindata -nocompress -o archive_bindata/archive_data.go -prefix "archive_bindata" -pkg archive_bindata archive_bindata/test_archive.tar.xz
Due to the increase in size, i am unable to use the asset in my code and compile/build in a machine with 32G of RAM.
Does go-bindata
decompresses the data before and then generate the arrays? How do i fix this to consider the archive as a normal file?
Hi.
I tried to use this lib in a project, but i get the following when i try to go-get it:
$ go get -u github.com/go-bindata/go-bindata/...
github.com/go-bindata/[email protected]: verifying module: checksum mismatch
downloaded: h1:upAQEGKG3hFv00/4cU/VhzF+NpCHz+Jk3rO946wWr+A=
sum.golang.org: h1:DZ34txDXWn1DyWa+vQf7V9ANc2ILTtrEjtlsdJRF26M=
SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.
For more information, see 'go help module-auth'.
Is this a known issue?
br.
Is it possible to include metadata e.g version of the included binary assets and being able to access them at runtime? This would enable to do additional runtime checks e.g. that the expected version of the asset was loaded and to log info about the loaded assets.
So, I'm trying to install this package, and the installation instructions are
go get -u github.com/go-bindata/go-bindata/...
Am I supposed to type something where the ellipses are?
data, err :=Asset("conf/app.ini")
err == nil
Test: (normal)
data, err :=Asset("conf/adasdasapp.ini")
err != nil
But: (unexpected result)
data, err :=Asset("conf/app.inis")
err==nil
I think this is a bug, I hope that the automatically generated bindata.go file can improve this suffix judgment
These files are generated by make for testing:
We do not need to keep them in source.
hello, in windows 10 system, exec this commond throw error, like buttom:
D:\goProject\go-blog\html>go-bindata -o ../data/bindata.go -fs -prefix "./" ./...
flag provided but not defined: -fs
Usage: go-bindata [options]
-debug
Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.
-dev ......
my env like buttom
D:\goProject\go-blog\html>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\yhm\AppData\Local\go-build
set GOENV=C:\Users\yhm\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\yhm\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\yhm\go
set GOPRIVATE=
set GOPROXY=https://goproxy.io
set GOROOT=D:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\goProject\go-blog\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\yhm\AppData\Local\Temp\go-build1760826101=/tmp/go-build -gno-record-gcc-switches
thanks
file _2_insert_keyboard_up.sql
don't use underscores in Go names; func _2_insert_keyboardUpSqlBytes should be _2InsertKeyboardUpSQLBytes
Perhaps a niche use case, but I need to load SPIR-V shaders as []uint32 for Vulkan. Currently, I have to first load it into a []byte and then write it into a []uint32 via encoding/binary.Read, using twice as much memory.
These are the exported functions created in the bindata file. Have an option to not write them (or make them not exposed) for people that don't want to expose a public API from this tool.
Hello, the original author. I'm glad to ask such a question, that is, after the web page of the proxies pool is edited (HTML static file), what command should be executed on SSH to make it effective? Thank you for your answer!
These Errorf
calls could take advantage of the new %w
support in 1.13 so the underlying error can still be accessed and queried easily, just change %v to %w.
webui/static.go: return nil, fmt.Errorf("Read %q: %v", name, err)
webui/static.go: return nil, fmt.Errorf("Read %q: %v", name, err)
webui/static.go: return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
webui/static.go: return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
I'm not sure your policy on supporting older Go versions but perhaps go-bindata could only emit this code if running in Go 1.13+.
Use case: the go-bindata is used to embed text/template and html/template sources which require to "compile" them (Parse) before use.
After parsing there are source and parsed template which increase used RAM.
Will be useful to have something like cleanAsset(name string) to drop any data of underlying var and remove it key from _bindata map.
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.