Giter VIP home page Giter VIP logo

go-bindata's Introduction

bindata

Build Status Go Report Card

This package converts any file into manageable Go source code. Useful for embedding binary data into a go program. The file data is optionally gzip compressed before being converted to a raw byte slice.

It comes with a command line tool in the go-bindata sub directory. This tool offers a set of command line options, used to customize the output being generated.

Installation

To install the library and command line program, use the following:

go get -u github.com/go-bindata/go-bindata/...

Usage

Conversion is done on one or more sets of files. They are all embedded in a new Go source file, along with a table of contents and an Asset function, which allows quick access to the asset, based on its name.

The simplest invocation generates a bindata.go file in the current working directory. It includes all assets from the data directory.

$ go-bindata data/

To include all input sub-directories recursively, use the ellipsis postfix as defined for Go import paths. Otherwise it will only consider assets in the input directory itself.

$ go-bindata data/...

To specify the name of the output file being generated, we use the following:

$ go-bindata -o myfile.go data/

Multiple input directories can be specified if necessary.

$ go-bindata dir1/... /path/to/dir2/... dir3

The following paragraphs detail some of the command line options which can be supplied to go-bindata. Refer to the testdata/out directory for various output examples from the assets in testdata/in. Each example uses different command line options.

To ignore files, pass in regexes using -ignore, for example:

$ go-bindata -ignore=\\.gitignore data/...

Accessing an asset

To access asset data, we use the Asset(string) ([]byte, error) function which is included in the generated output.

data, err := Asset("pub/style/foo.css")
if err != nil {
	// Asset was not found.
}

// use asset data

Debug vs Release builds

When invoking the program with the -debug flag, the generated code does not actually include the asset data. Instead, it generates function stubs which load the data from the original file on disk. The asset API remains identical between debug and release builds, so your code will not have to change.

This is useful during development when you expect the assets to change often. The host application using these assets uses the same API in both cases and will not have to care where the actual data comes from.

An example is a Go webserver with some embedded, static web content like HTML, JS and CSS files. While developing it, you do not want to rebuild the whole server and restart it every time you make a change to a bit of javascript. You just want to build and launch the server once. Then just press refresh in the browser to see those changes. Embedding the assets with the debug flag allows you to do just that. When you are finished developing and ready for deployment, just re-invoke go-bindata without the -debug flag. It will now embed the latest version of the assets.

Lower memory footprint

Using the -nomemcopy flag, will alter the way the output file is generated. It will employ a hack that allows us to read the file data directly from the compiled program's .rodata section. This ensures that when we call our generated function, we omit unnecessary memcopies.

The downside of this, is that it requires dependencies on the reflect and unsafe packages. These may be restricted on platforms like AppEngine and thus prevent you from using this mode.

Another disadvantage is that the byte slice we create, is strictly read-only. For most use-cases this is not a problem, but if you ever try to alter the returned byte slice, a runtime panic is thrown. Use this mode only on target platforms where memory constraints are an issue.

The default behaviour is to use the old code generation method. This prevents the two previously mentioned issues, but will employ at least one extra memcopy and thus increase memory requirements.

For instance, consider the following two examples:

This would be the default mode, using an extra memcopy but gives a safe implementation without dependencies on reflect and unsafe:

func myfile() []byte {
    return []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a}
}

Here is the same functionality, but uses the .rodata hack. The byte slice returned from this example can not be written to without generating a runtime error.

var _myfile = "\x89\x50\x4e\x47\x0d\x0a\x1a"

func myfile() []byte {
    var empty [0]byte
    sx := (*reflect.StringHeader)(unsafe.Pointer(&_myfile))
    b := empty[:]
    bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
    bx.Data = sx.Data
    bx.Len = len(_myfile)
    bx.Cap = bx.Len
    return b
}

Optional compression

When the -nocompress flag is given, the supplied resource is not GZIP compressed before being turned into Go code. The data should still be accessed through a function call, so nothing changes in the usage of the generated file.

This feature is useful if you do not care for compression, or the supplied resource is already compressed. Doing it again would not add any value and may even increase the size of the data.

The default behaviour of the program is to use compression.

Path prefix stripping

The keys used in the _bindata map, are the same as the input file name passed to go-bindata. This includes the path. In most cases, this is not desirable, as it puts potentially sensitive information in your code base. For this purpose, the tool supplies another command line flag -prefix. This accepts a portion of a path name, which should be stripped off from the map keys and function names.

For example, running without the -prefix flag, we get:

$ go-bindata /path/to/templates/

_bindata["/path/to/templates/foo.html"] = path_to_templates_foo_html

Running with the -prefix flag, we get:

$ go-bindata -prefix "/path/to/" /path/to/templates/

_bindata["templates/foo.html"] = templates_foo_html

Build tags

With the optional -tags flag, you can specify any go build tags that must be fulfilled for the output file to be included in a build. This is useful when including binary data in multiple formats, where the desired format is specified at build time with the appropriate tags.

The tags are appended to a // +build line in the beginning of the output file and must follow the build tags syntax specified by the go tool.

Serve assets with net/http

With the -fs flag, go-bindata will add an AssetFile() method returning an http.FileSystem interface:

$ go-bindata -fs -prefix "static/" static/

Use -prefix flag to strip first level dir, then in your net/http router, you can use AssetFile() with http.FileServer() like:

mux := http.NewServeMux()
mux.Handle("/static", http.FileServer(AssetFile()))
http.ListenAndServe(":8080", mux)

go-bindata's People

Contributors

alimy avatar bassosimone avatar byron avatar christoph-k avatar craig-landry avatar dmitshur avatar elazarl avatar ferhatelmas avatar grobie avatar ikawaha avatar inconshreveable avatar jsoref avatar jwforres avatar krhubert avatar liggitt avatar liweiv avatar mattn avatar narg95 avatar nathanjordan avatar octplane avatar philoserf avatar riywo avatar srhnsn avatar stephens2424 avatar taichi avatar tamird avatar tbg avatar tennyzhuang avatar volker-raschek avatar yosssi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-bindata's Issues

gosec error - Potential DoS vulnerability via decompression

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

checksum mismatch

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.

Maintainer?

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.

DEB- and RPM-package

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.

Execute binary in memory

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) ?

Error: no migration found

Hi guys, why I got this error ya?

image

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

zsh: command not found: go-bindata

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.

go mod support

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.

-debug generates wrong output (bindataFileInfo struct is missing)

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.

Remove generated files from testdata.out directory tree

These files are generated by make for testing:

  • testdata/out/compress-memcopy.go
  • testdata/out/compress-nomemcopy.go
  • testdata/out/debug.go
  • testdata/out/nocompress-memcopy.go
  • testdata/out/nocompress-nomemcopy.go

We do not need to keep them in source.

specifies the compression level support?

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.

bfd := bufio.NewWriter(fd)

gz := gzip.NewWriter(&StringWriter{Writer: w})

gz := gzip.NewWriter(&StringWriter{Writer: w})

/path/to/asset should treat as path/to/asset

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.
image

without "/" prefix, IDE resolve the path with current file's directory, but my assets are under the project root directory.
image

so if go-bindata treats /path/to/asset as path/to/asset, it will be pretty nice.

go-bindata command not working

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

bindataFileInfo not defined when using -debug

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{}}
}

Files beginning with a "." become exported

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:

  • maybe ignore hidden files by default? Add a "-hidden" flag to include hidden files?
  • at least fix the generated code to always produce unexported names. I'm not sure it's necessary to generate functions for each asset, seems like a map/slice + struct would do.
  • log names added to the bundle to stderr

add json data

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
}
}
]

web edit

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!

generating with -debug -fs results in compile error

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!

container image

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 " ]

Error Strings Start With Capital Letters

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?

Metadata about binary assets

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.

use gin-bindata in gin and vue

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")
	})
}

Packing a XZ compressed archive makes the asset file size bigger than original

❯ 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?

Don't emit modified Go if underlying assets haven't changed

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?

centos build arm run error

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?

你好,windows 10下运行报错

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

I got a bug about Asset

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

Use Go 1.13's new wrapped error support

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+.

Not reading subdirectories

go-bindata -pkg frontend -o libs/frontend/data.go -nometadata ../frontend/...

directory structure looks liek this:

  • frontend/public/controller/index.html
  • frontend/public/component/header.html
  • frontend/public/component/footer.html

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

go-staticcheck linter warnings in generated code

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:

  1. update the codegen to avoid these warnings
  2. emit //lint:file-ignore (or a rule-specific ignore) to silence the warnings
  3. hack around it locally

What do you think? I'm happy to put up a PR once there is a decision

Screenshots:

image

image

Unable to generate bindata with go 1.11

Simple test:

  • Create a bintest dir directory with binary files
  • Run go-bindata -pkg bintestout -o ./bintestout/files.go ./bintest/*
  • File generated has syntax errors
    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.

Commit reference

`-prefix` still shows prefix in comments

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

404 when hosting using `-fs` and hosting over `net/http`

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.

Specify word size and endianness for loaded assets

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.

Feature: add ability to completely clean embedded binary content at run time

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.

installation instruction not working with go1.17.1

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'.

binary releases ?

would be nice to have binary releases, as go-bindata is used so much in CI etc, and its easier to pull a binary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.