What's the best way to bundle static resources in a Go program? -


i'm working on small web application in go that's meant used tool on developer's machine debug applications/web services. interface program web page includes not html, javascript (for functionality), images , css (for styling). i'm planning on open-sourcing application, users should able run makefile , resources go need go. however, i'd able distribute executable few files/dependencies possible. is there way bundle html/css/js executable, users have download , worry 1 file?


right now, in app, serving static file looks little this:

// called via http.listenandserve func switchboard(w http.responsewriter, r *http.request) {      // snipped dynamic routing...      // static resource     uri := r.url.requesturi()     if fp, err := os.open("static" + uri); err == nil {         defer fp.close()         statichandler(w, r, fp)         return     }      // snipped blackhole route } 

so it's pretty simple: if requested file exists in static directory, invoke handler, opens file , tries set content-type before serving. thought there's no reason needs based on real filesystem: if there compiled resources, index them request uri , serve them such.

if there's not way this, or i'm barking wrong tree trying this, let me know. figured end-user appreciate few files possible manage.

if there more appropriate tags , please feel free add them or let me know.

the go-bindata package looks might you're interested in.

https://github.com/jteeuwen/go-bindata

it allow convert static file function call can embedded in code , return byte slice of file content when called.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -