bee icon indicating copy to clipboard operation
bee copied to clipboard

Use go-bindata to pack all the static files to a single binary when build the project

Open uptoknow opened this issue 9 years ago • 14 comments
trafficstars

Currently, we can use bee pack to generate a tar.gz which include , if we can pack all the static files into a single binary file it will be convenient for us.

uptoknow avatar Nov 07 '16 12:11 uptoknow

yea, I am still working on that.

astaxie avatar Nov 07 '16 14:11 astaxie

@uptoknow I think you should use go bale. It will read all your static files in the specified dirs (*.js, *.css) and generate a *.go file per static file (something like static_js_jquery_xxx.go) inside a bale folder.

If you use a bee.json file, you can add it like this:

...
"bale":{
   "dirs": ["static/js", "static/css"]
}
...

amrfaissal avatar Nov 07 '16 14:11 amrfaissal

@amrfaissal Different than what I request, I want the "bee pack" or some command can help generate a single binary file instead of using go bale to generate the *.go file, and use it some where.

uptoknow avatar Nov 08 '16 02:11 uptoknow

@astaxie Have you already prepare an pr? when you plan to add this? I am glad to help if you don't have more time on it.

uptoknow avatar Nov 08 '16 02:11 uptoknow

@uptoknow it's still on the schedule. not working on it. If you can work on it, that would be awesome.

astaxie avatar Nov 08 '16 02:11 astaxie

@astaxie Have a quick look of the code, if we want to implement this feature we need

  1. When generate the view template, we need read data from go-bindata generate Asset, instead of read from absoluateFilePath
  2. Which means we need generate the bindata when run ''bee new"

How do you think about this ?

uptoknow avatar Nov 08 '16 15:11 uptoknow

it looks need to implement an interface: TemplateData(path string) ([]byte,error), the default is fileHandler,and if we use the go-bindata we can reimplement the interface.

astaxie avatar Nov 09 '16 12:11 astaxie

@astaxie Yeah, I will try to prepare a PR when I can.

uptoknow avatar Nov 09 '16 14:11 uptoknow

@astaxie Met a problem, when we decide to use the go-bindata handler? and how we implement the go-bindata handler based on the current framework, go-bindata is a tool to generate the static go file, and we can use the function Asset("path to the template/file") to generate the data which is difficult for beego to use a after generated function. do you have any idea about this ?

uptoknow avatar Nov 14 '16 08:11 uptoknow

@uptoknow my idea is write a subcommand like bee bale. which all the static files turn into []byte go files, and generate an interface Asset(path) io.Reader. So beego has a config which read from interface which default is set to static. and when we also can overwrite it with the generate interface. That's the general idea.

astaxie avatar Nov 14 '16 13:11 astaxie

@uptoknow @astaxie support set Asset func for the template #2402 I've apply the patch , and use

go-bindata.exe -o myview.go views/...

to get sourcecode which contains Asset(..) function. and delete all files in views/ dir. and in my main.go 's init() function set

beego.SetTmplateAssetFunc(Asset)

all compile ok,but execute still get waring

Handler crashed with error can't find templatefile in the views/.....

so, I've no idea now :q

Any tips ?

kerneltravel avatar Sep 04 '17 03:09 kerneltravel

@uptoknow @astaxie Hi! I'm add views storage configuration Add custom fs template With it, you can use https://github.com/elazarl/go-bindata-assetfs

lxShaDoWxl avatar Nov 06 '18 16:11 lxShaDoWxl

Can I get a windows binary out of the project. With a .exe extension to deploy on windows server??

If so please let me know how.

vikram-rawat avatar Jan 26 '19 15:01 vikram-rawat

Shouldn't this Issue be updated to use Go 1.16 embed package?

alwindoss avatar Feb 23 '21 16:02 alwindoss