nrsc /

Filename Size Date modified Message
47 B
13 B
72 B
47 B
1.1 KB
2.2 KB
2.2 KB
3.7 KB
3.6 KB

nrsc - Resource Compiler for Go

nrsc compiles a directory of resource into a Go source file so you can still deploy a single executable as a web server with all the CSS, image files, JS ... included.


go get


nrsc path_to_resource_dir

This will create a local directory called nrsc which you can import in your code.


The nrsc package has the following interface

nrsc.Handle(prefix string)

This will register with the net/http module to handle all paths starting with prefix.

When a request is handled, prefix is stripped and then a resource is located and served.

Resource that are not found will cause an HTTP 404 response.

nrsc.Get(path string) Resource
Will return a resource interface (or nil if not found) (see resource interface below). This allows you more control on how to serve.
LoadTemplates(t *template.Template, filenames ...string) (*template.Template, error)
Will load named templates from resources. If the argument "t" is nil, it is created from the first resource.

Resource Interface

func Open() io.Reader
Returns a reader to resource data
func Size() int64
Returns resource size (to be used with Content-Length HTTP header).
func ModTime() time.Time
Returns modification time (to be used with Last-Modified HTTP header).

Example Code

package main

import (


func indexHandler(w http.ResponseWriter, req *http.Request) {
        fmt.Fprintf(w, "Hello World\n")

func main() {
        http.HandleFunc("/", indexHandler)
        if err := http.ListenAndServe(":8080", nil); err != nil {
                fmt.Fprintf(os.Stderr, "error: %s\n", err)


MIT (see LICENSE.txt)

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.