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

generate bytes #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

generate bytes #79

wants to merge 1 commit into from

Conversation

speier
Copy link

@speier speier commented Apr 2, 2020

public method to return output bytes instead of writing directly to file, can be useful to use the output in various ways during generation before writing to file.

same signature as Generate(), for example:

err := vfsgen.GenerateBytes(http.Dir("assets"), vfsgen.Options{})

@dmitshur
Copy link
Member

dmitshur commented Apr 2, 2020

can be useful to use the output in various ways during generation

Can you please elaborate on the use case? What problem is the new API intending to solve? Thanks.

@speier
Copy link
Author

speier commented Apr 2, 2020

in my case for example, i'm appending an additional func to the end of the output before writing to file...

main.go

var assets http.FileSystem = http.Dir("dist")

assets_generate.go

b, err := vfsgen.GenerateBytes(http.Dir(“/tmp/build/dist”), vfsgen.Options{
    VariableName: "assetsFS",
})
...
writeStub(b) // append init stub and write output to file

output assets_vfsdata.go

var assetsFS = func() http.FileSystem { .... }()
...
func init() { assets = assetsFS }

with this i can "override" the assets variable specified in main without build tags.
bit hacky but this worked best in our CI pipeline with Bazel build.

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

Successfully merging this pull request may close these issues.

None yet

2 participants