github.com/carbocation/gotogether@v0.0.0-20130502180533-aa88e503440f/README.rst (about) 1 `gotogether` - Resource Compiler for Go 2 ================================= 3 4 `gotogether` a directory of resource into a Go source file so you can still 5 deploy a single executable as a web server with all the CSS, image files, JS ... 6 included. 7 8 This is a fork of tebeka's nrsc: http://bitbucket.org/tebeka/nrsc 9 10 Installing 11 ========== 12 :: 13 14 go get github.com/carbocation/gotogether 15 16 Also grab the `gotogether` script from here_ 17 18 And you'll need `zip` somewhere in your path. 19 20 .. _here: http://bit.ly/gotogether-script 21 22 Invocation 23 ========== 24 :: 25 26 go build 27 gotogether <executable> <resource dir> [zip options] 28 29 30 API 31 === 32 The `gotogether` package has the following interface 33 34 `gotogether.Handle(prefix string)` 35 This will register with the `net/http` module to handle all paths starting with prefix. 36 37 When a request is handled, `prefix` is stripped and then a resource is 38 located and served. 39 40 Resource that are not found will cause an HTTP 404 response. 41 42 43 `gotogether.Get(path string) Resource` 44 Will return a resource interface (or `nil` if not found) (see resource interface below). 45 This allows you more control on how to serve. 46 47 48 `LoadTemplates(t *template.Template, filenames ...string) (*template.Template, error)` 49 Will load named templates from resources. If the argument "t" is `nil`, it is 50 created from the first resource. 51 52 Resource Interface 53 ------------------ 54 55 `func Open() (io.Reader, error)` 56 Returns a reader to resource data 57 58 `func Size() int64` 59 Returns resource size (to be used with `Content-Length` HTTP header). 60 61 `func ModTime() time.Time` 62 Returns modification time (to be used with `Last-Modified` HTTP header). 63 64 65 Example Code 66 ------------ 67 :: 68 69 package main 70 71 import ( 72 "fmt" 73 "net/http" 74 "os" 75 76 "github.com/carbocation/gotogether" 77 ) 78 79 func indexHandler(w http.ResponseWriter, req *http.Request) { 80 fmt.Fprintf(w, "Hello World\n") 81 } 82 83 func main() { 84 gotogether.Handle("/static/") 85 http.HandleFunc("/", indexHandler) 86 if err := http.ListenAndServe(":8080", nil); err != nil { 87 fmt.Fprintf(os.Stderr, "error: %s\n", err) 88 os.Exit(1) 89 } 90 } 91 92 Contact 93 ======= 94 https://github.com/carbocation/gotogether 95 96 License 97 ======= 98 MIT (see `LICENSE.txt`_) 99 100 .. _`LICENSE.txt`: https://github.com/carbocation/gotogether/src/tip/LICENSE.txt