func leveldbOpener(url *config.URL) (driver.Driver, error) { value := url.Value if !filepath.IsAbs(value) { value = pathutil.Relative(value) } opts := &opt.Options{} if url.Fragment["nocompress"] != "" { opts.Compression = opt.NoCompression } if url.Fragment["nocreate"] != "" { opts.ErrorIfMissing = true } filesDir := filepath.Join(value, "files") files, err := leveldb.OpenFile(filesDir, opts) if err != nil { return nil, err } copts := *opts copts.Filter = filter.NewBloomFilter(8 * sha1.Size) chunksDir := filepath.Join(value, "chunks") chunks, err := leveldb.OpenFile(chunksDir, &copts) if err != nil { return nil, err } return &leveldbDriver{ files: files, chunks: chunks, dir: value, }, nil }
func init() { template.AddFuncs(template.FuncMap{ "#config": func(name string, def string) template.HTML { var buf bytes.Buffer buf.WriteString("<h3 class=\"config\">") buf.WriteString(html.Escape(name)) if def != "" { buf.WriteString(" <span class=\"label label-success\">optional</span>") fmt.Fprintf(&buf, " <span class=\"default\">default: %s</span>", html.Escape(def)) } else { buf.WriteString(" <span class=\"label label-danger\">required</span>") } buf.WriteString("</h3>") return template.HTML(buf.String()) }}) config.MustParse() App = app.New() App.SetTrustXHeaders(true) // Redirect all other possible hosts to governator.io redir := app.RedirectHandler("http://governator.io${0}", true) App.Handle("(.*)", redir, app.HostHandler("governator-io.appspot.com")) App.Handle("(.*)", redir, app.HostHandler("www.governator.io")) App.HandleAssets("/assets/", pathutil.Relative("assets")) App.Handle("^/$", app.TemplateHandler("main.html", nil)) App.Handle("^/install\\.sh$", fileHandler("contrib/install.sh")) App.Handle("^/get/releases/linux/x86_64/latest/governator$", fileHandler("governator")) App.Handle("^/contrib/(.*)", func(ctx *app.Context) { path := filepath.Join(data, "contrib", filepath.FromSlash(ctx.IndexValue(0))) serveFile(ctx, path) }) }
func fsOpener(url *config.URL) (Driver, error) { value := filepath.FromSlash(url.Value) if !filepath.IsAbs(value) { value = pathutil.Relative(value) } return &FileSystemDriver{Root: value}, nil }
// DefaultVFS returns a VFS which loads templates from // the tmpl directory, relative to the application binary. func DefaultVFS() vfs.VFS { fs, err := vfs.FS(pathutil.Relative("tmpl")) if err != nil { // Very unlikely, since FS only fails when // os.Getwd() fails. panic(err) } return fs }
func fsOpener(url *config.URL) (driver.Driver, error) { value := url.Value if !filepath.IsAbs(value) { value = pathutil.Relative(value) } tmpDir := filepath.Join(value, "tmp") if url.Fragment["nocreate"] != "" && !fileutil.DirExists(tmpDir) { return nil, fmt.Errorf("no file based blobstore found at %s", tmpDir) } if err := os.MkdirAll(tmpDir, 0755); err != nil { return nil, err } return &fsDriver{ dir: value, tmpDir: tmpDir, }, nil }
func init() { if internal.InAppEngineDevServer() { DefaultFilename = pathutil.Relative("dev.conf") } }
"fmt" "io" "os" "reflect" "strconv" "strings" "gnd.la/form/input" "gnd.la/internal" "gnd.la/util/pathutil" "gnd.la/util/stringutil" "gnd.la/util/types" ) var ( DefaultFilename = pathutil.Relative("app.conf") configName *string ) type fieldValue struct { Value reflect.Value Tag reflect.StructTag } type fieldMap map[string]*fieldValue func (f fieldMap) Append(name string, value reflect.Value, tag reflect.StructTag) error { if _, ok := f[name]; ok { return fmt.Errorf("duplicate field name %q", name) } f[name] = &fieldValue{value, tag}
"net/http" "os" "path/filepath" "time" "gnd.la/app" "gnd.la/config" _ "gnd.la/frontend/bootstrap" "gnd.la/html" "gnd.la/template" "gnd.la/util/pathutil" ) var ( App *app.App data = pathutil.Relative("data") ) func fileHandler(name string) app.Handler { p := filepath.Join(data, name) return func(ctx *app.Context) { serveFile(ctx, p) } } func serveFile(ctx *app.Context, path string) { f, err := os.Open(path) if err != nil { ctx.NotFound("") return }