talks / nrsc.slide

Full commit
Packing Resource in Go Executables
Tags: go

Miki Tebeka
Lead Software Engineer, Demand Media

* The Good, the Bad and the Ugly
- Good:  Go is statically linked, we need to ship *one* binary.
- Bad: Web application (and others) need some external resources
- Ugly: `nrsc` lets you embed resources in Go executables

* Method
- Use `cat` to append zipped resource to executable
- Use `zip`-A` to "fix" offset
- Use `nrsc` library to access resources

(Original idea from [[][Carlos Castillo in golang-nuts list]])

* nrsc shell script
.code nrsc/nrsc  /START/,/END/

* Resource
.code nrsc/nrsc.go  /START_DEF/,/END_DEF/

* Loading (1)
.code nrsc/nrsc.go  /START_MAP_1/,/END_MAP_1/

* Loading (2)
.code nrsc/nrsc.go  /START_MAP_2/,/END_MAP_2/

* Get
.code nrsc/nrsc.go  /START_GET/,/END_GET/

* Masking
.code nrsc/nrsc.go  /START_MASK/,/END_MASK/

* Serving (1)
.code nrsc/nrsc.go  /START_SERVE1/,/END_SERVE1/

* Serving (2)
.code nrsc/nrsc.go  /START_SERVE2/,/END_SERVE2/

* Handle
.code nrsc/nrsc.go  /START_HANDLE/,/END_HANDLE/

* Testing

- Create an executable with embedded resources in /tmp
- Run it (it's a web server)
- Test methods (hit, miss, mask ...)
- Kill server

See [[][nrsc_test.go]]

* Future Work

Help is highly appreciated :)

- Convert nrsc bash script to Go code ([[][issue #2]])
    - Make it "go gettable"
- Remove external depedency on zip ([[][issue #4]])
    - Windows anyone?
- Use `fuse` and provide file system API to resource ([[][issue #3]])
    - Simplify a lot of things (LoadTemplate ...)
    - However totally different API
- Get rid of `Initialize` ([[][issue #5]])
    - `loadMap` in `init` does not work

* References
- [[]]