|
@@ -1,2 +1,44 @@
|
|
|
# vessel
|
|
|
+Implements a golang library and command line tool for embedding contents of a zip file into a golang binary for the
|
|
|
+purpose of packing the binary and content into a single file for distribution.
|
|
|
+
|
|
|
+The zip file is appended to the back of the binary, and the provided API allows us to access the zipped
|
|
|
+files directly.
|
|
|
+
|
|
|
+
|
|
|
+# bundling
|
|
|
+
|
|
|
+In the example below, vesselcmd will zip up the content of **site/** and attach it to the golang binary **server**
|
|
|
+```
|
|
|
+./vesselcmd build --overwrite --bundle=./server.exe --src=site/
|
|
|
+```
|
|
|
+
|
|
|
+# Accessing the bundled resources
|
|
|
+
|
|
|
+Once bundled the golang program can acess the content via:
|
|
|
+```
|
|
|
+ b, err := vessel.Self()
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ fs := b.FileSystem() // this returns an htp.FileSyste
|
|
|
+```
|
|
|
+
|
|
|
+We can then directly use the returned filesystem to serve http pages/content
|
|
|
+```
|
|
|
+ http.Handle("/", http.FileServer(fs))
|
|
|
+```
|
|
|
+
|
|
|
+Or we can access the files ourselves by using the http.FileSystem interfaces
|
|
|
+```
|
|
|
+ f, err := fs.Open("/templates/list.html")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+ data, err := ioutil.ReadAll(f)
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
|