nrsc: bitbucket.org/tebeka/nrsc Index | Files | Directories

package nrsc

import "bitbucket.org/tebeka/nrsc"

Serving resource from zip file appended to Go executable (this enables on file deploy).

Making it happen:

1. Add code to serve resources (see example below)
2. Compile your executable
3. Run "nrsc /path/to/exe /path/to/resources"
4. Deploy

Example code:

package main

import (
	"fmt"
	"net/http"
	"os"

	"bitbucket.org/tebeka/nrsc"
)

type params struct {
	Number  int
}

func indexHandler(w http.ResponseWriter, req *http.Request) {
	t, err := nrsc.LoadTemplates(nil, "t.html")
	if err != nil {
		http.NotFound(w, req)
	}
	if err = t.Execute(w, params{7}); err != nil {
		http.NotFound(w, req)
	}
}

func main() {
	nrsc.Handle("/static/")
	nrsc.Mask(".tmpl$")
	http.HandleFunc("/", indexHandler)
	if err := http.ListenAndServe(":8080", nil); err != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", err)
		os.Exit(1)
	}
}

Index

Package Files

doc.go nrsc.go

Constants

const (
    Version = "0.4.1"
)

Variables

var ResourceMap map[string]Resource = nil

func Handle Uses

func Handle(prefix string) error

Handle register HTTP handler under prefix

func Initialize Uses

func Initialize() error

func LoadTemplates Uses

func LoadTemplates(t *template.Template, filenames ...string) (*template.Template, error)

LoadTemplates loads named templates from resources. If the argument "t" is nil, it is created from the first resource.

func Mask Uses

func Mask(mask *regexp.Regexp)

Mask masks URLs from being served (the HTTP server will return 401 Unauthorized)

type Resource Uses

type Resource interface {
    Name() string
    Open() (io.ReadCloser, error)
    Size() int64
    ModTime() time.Time
}

func Get Uses

func Get(path string) Resource

Get returns the named resource (nil if not found)

Directories

PathSynopsis
nrsc

Package nrsc imports 14 packages (graph) and is imported by 1 packages. Updated 2016-07-17. Refresh now. Tools for package owners.