示例#1
0
func init() {
	server := env.GetDefault("MEMCACHE_SERVERS", "")
	if server == "" {
		impl = newDictCache()
	} else {
		impl = newMemcacheCache(server, env.GetDefault("MEMCACHE_USERNAME", ""), env.GetDefault("MEMCACHE_PASSWORD", ""))
	}
}
示例#2
0
func init() {
	cs, err := ioutil.ReadFile(CoffeeScriptPath)
	if err != nil {
		panic(fmt.Sprintf("Failed reading bookmarklet: %s", err))
	}
	script = cs

	precompile := env.GetDefault("BOOKMARKLET_PRECOMPILE", "")
	if precompile != "" {
		js := Compile(precompile == "ugly")
		bm = Marker{func() []byte {
			return js
		}}
	} else {
		bm = Marker{func() []byte {
			return Compile(false)
		}}
	}
}
示例#3
0
	"github.com/garyburd/twister/pprof"
	"github.com/garyburd/twister/server"
	"github.com/garyburd/twister/web"
	"html/template"
	"io"
	"job"
	"log"
	"net"
	"os"
	"regexp"
)

type JSON map[string]interface{}

var doneRegex = regexp.MustCompile("(?i:done|failed|limited|invalid|error|sorry)")
var canonicalHost = env.GetDefault("CANONICAL_HOST", fmt.Sprintf("localhost:%s", port))
var port = env.GetDefault("PORT", "8080")
var logger = log.New(os.Stdout, "[server] ", log.LstdFlags|log.Lmicroseconds)
var templates = template.Must(template.ParseGlob("views/*.tmpl"))

func renderPage(w io.Writer, page, host string) error {
	buffer := new(bytes.Buffer)
	if err := templates.ExecuteTemplate(buffer, page, nil); err != nil {
		return err
	}
	return templates.ExecuteTemplate(w, "layout.tmpl", JSON{
		"host":  host,
		"yield": template.HTML(buffer.String()),
	})
}