Пример #1
0
func prepare(t *testing.T) aetest.Context {

	lg, lge := loghttp.Logger(nil, nil)
	_ = lg

	c, err := aetest.NewContext(nil)
	if err != nil {
		lge(err)
		t.Fatal(err)
	}

	serveFile := func(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
		fs1 := repo.GetFS(c)
		fileserver.FsiFileServer(w, r, fileserver.Options{FS: fs1, Prefix: repo.UriMountNameY})
	}
	http.HandleFunc(repo.UriMountNameY, loghttp.Adapter(serveFile))

	go func() {
		log.Fatal(
			http.ListenAndServe(cTestHostOwn, nil),
		)
	}()

	return c

}
Пример #2
0
// We cannot use http.FileServer(http.Dir("./css/") to dispatch our dsfs files.
// We need the appengine context to initialize dsfs.
//
// Thus we re-implement a serveFile method:
func ServeDsFsFile(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	urlPath := m["dir"].(string)
	if len(urlPath) > 0 {
		urlPath = urlPath[1:]
	}

	prefix := "/mnt00"

	pos := strings.Index(urlPath, "/")
	if pos > 0 {
		prefix = "/" + urlPath[:pos]
	}
	if pos == -1 {
		prefix = "/" + urlPath
	}

	fs2 := dsfs.New(
		dsfs.MountName(prefix[1:]),
		dsfs.AeContext(appengine.NewContext(r)),
	)

	fileserver.FsiFileServer(w, r, fileserver.Options{FS: fs2, Prefix: prefix + "/"})

}
Пример #3
0
// serveFile makes the previously fetched files available like
// a static fileserver.
func serveFile(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {
	fs1 := GetFS(appengine.NewContext(r))
	fileserver.FsiFileServer(w, r, fileserver.Options{FS: fs1, Prefix: UriMountNameY})
}