当前位置: 首页>>代码示例>>Golang>>正文


Golang ricetemp.MustMakeTemplates函数代码示例

本文整理汇总了Golang中github.com/cortesi/devd/ricetemp.MustMakeTemplates函数的典型用法代码示例。如果您正苦于以下问题:Golang MustMakeTemplates函数的具体用法?Golang MustMakeTemplates怎么用?Golang MustMakeTemplates使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MustMakeTemplates函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestLinuxSendfileChild

// TestLinuxSendfileChild isn't a real test. It's used as a helper process
// for TestLinuxSendfile.
func TestLinuxSendfileChild(*testing.T) {
	if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
		return
	}
	defer os.Exit(0)
	fd3 := os.NewFile(3, "ephemeral-port-listener")
	ln, err := net.FileListener(fd3)
	if err != nil {
		panic(err)
	}
	mux := http.NewServeMux()

	fs := &FileServer{
		http.Dir("testdata"),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
	}

	mux.Handle("/", fs)
	mux.HandleFunc("/quit", func(http.ResponseWriter, *http.Request) {
		os.Exit(0)
	})
	s := &http.Server{Handler: mux}
	err = s.Serve(ln)
	if err != nil {
		panic(err)
	}
}
开发者ID:homburg,项目名称:devd,代码行数:30,代码来源:fileserver_test.go

示例2: TestServeIndexHtml

func TestServeIndexHtml(t *testing.T) {
	defer afterTest(t)
	const want = "index.html says hello\n"

	fs := &FileServer{
		http.Dir("."),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
	}
	ts := httptest.NewServer(fs)
	defer ts.Close()

	for _, path := range []string{"/testdata/", "/testdata/index.html"} {
		res, err := http.Get(ts.URL + path)
		if err != nil {
			t.Fatal(err)
		}
		b, err := ioutil.ReadAll(res.Body)
		if err != nil {
			t.Fatal("reading Body:", err)
		}
		if s := string(b); s != want {
			t.Errorf("for path %q got %q, want %q", path, s, want)
		}
		res.Body.Close()
	}
}
开发者ID:homburg,项目名称:devd,代码行数:27,代码来源:fileserver_test.go

示例3: TestFSRedirect

func TestFSRedirect(t *testing.T) {
	defer afterTest(t)
	ts := httptest.NewServer(
		http.StripPrefix(
			"/test",
			&FileServer{
				http.Dir("."),
				inject.CopyInject{},
				ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
			},
		),
	)
	defer ts.Close()

	for _, data := range fsRedirectTestData {
		res, err := http.Get(ts.URL + data.original)
		if err != nil {
			t.Fatal(err)
		}
		res.Body.Close()
		if g, e := res.Request.URL.Path, data.redirect; g != e {
			t.Errorf("redirect from %s: got %s, want %s", data.original, g, e)
		}
	}
}
开发者ID:homburg,项目名称:devd,代码行数:25,代码来源:fileserver_test.go

示例4: TestFileServerCleans

func TestFileServerCleans(t *testing.T) {
	defer afterTest(t)
	ch := make(chan string, 1)
	fs := &FileServer{
		&testFileSystem{
			func(name string) (http.File, error) {
				ch <- name
				return nil, errors.New("file does not exist")
			},
		},
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
	}
	tests := []struct {
		reqPath, openArg string
	}{
		{"/foo.txt", "/foo.txt"},
		{"//foo.txt", "/foo.txt"},
		{"/../foo.txt", "/foo.txt"},
	}
	req, _ := http.NewRequest("GET", "http://example.com", nil)
	for n, test := range tests {
		rec := httptest.NewRecorder()
		req.URL.Path = test.reqPath
		fs.ServeHTTP(rec, req)
		if got := <-ch; got != test.openArg {
			t.Errorf("test %d: got %q, want %q", n, got, test.openArg)
		}
	}
}
开发者ID:homburg,项目名称:devd,代码行数:30,代码来源:fileserver_test.go

示例5: TestFileServerZeroByte

func TestFileServerZeroByte(t *testing.T) {
	defer afterTest(t)
	fs := &FileServer{
		"version",
		http.Dir("."),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
		[]routespec.RouteSpec{},
		"",
	}
	ts := httptest.NewServer(fs)
	defer ts.Close()

	res, err := http.Get(ts.URL + "/..\x00")
	if err != nil {
		t.Fatal(err)
	}
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		t.Fatal("reading Body:", err)
	}
	if res.StatusCode == 200 {
		t.Errorf("got status 200; want an error. Body is:\n%s", string(b))
	}
}
开发者ID:cortesi,项目名称:devd,代码行数:25,代码来源:fileserver_test.go

示例6: TestDevdRouteHandler

func TestDevdRouteHandler(t *testing.T) {
	logger := termlog.NewLog()
	logger.Quiet()
	r := Route{"", "/", fsEndpoint("./testdata")}
	templates := ricetemp.MustMakeTemplates(rice.MustFindBox("templates"))

	devd := Devd{
		Routes:      make([]string, 0, 0),
		OpenBrowser: false,
		CertFile:    "",
		Address:     "",
		Port:        0,

		// Shaping
		Latency:  0,
		DownKbps: 0,
		UpKbps:   0,

		// Livereload
		LivereloadRoutes: false,
		Watch:            make([]string, 0, 0),
		Excludes:         make([]string, 0, 0),

		// Logging
		IgnoreLogs: make([]string, 0, 0),
	}

	h := devd.RouteHandler(logger, r, templates, nil)
	ht := handlerTester{t, h}

	AssertCode(t, ht.Request("GET", "/", nil), 200)
}
开发者ID:supiyun,项目名称:devd,代码行数:32,代码来源:cli_test.go

示例7: TestDevdHandler

func TestDevdHandler(t *testing.T) {
	logger := termlog.DummyLogger{}
	r := Route{"", "/", fsEndpoint("./testdata")}
	templates := ricetemp.MustMakeTemplates(rice.MustFindBox("templates"))
	h := devdHandler(&logger, r, templates, true, nil, true, 0)
	ht := handlerTester{t, h}

	AssertCode(t, ht.Request("GET", "/", nil), 200)
}
开发者ID:npk,项目名称:devd,代码行数:9,代码来源:cli_test.go

示例8: ServeFile

// ServeFile replies to the request with the contents of the named file or directory.
func ServeFile(w http.ResponseWriter, r *http.Request, name string) {
	dir, file := filepath.Split(name)
	logger := termlog.DummyLogger{}

	fs := FileServer{
		http.Dir(dir),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
	}
	fs.serveFile(logger, w, r, file, false)
}
开发者ID:npk,项目名称:devd,代码行数:12,代码来源:fileserver_test.go

示例9: TestDevdRouteHandler

func TestDevdRouteHandler(t *testing.T) {
	logger := termlog.NewLog()
	logger.Quiet()
	r := Route{"", "/", fsEndpoint("./testdata")}
	templates := ricetemp.MustMakeTemplates(rice.MustFindBox("templates"))

	devd := Devd{LivereloadRoutes: true}
	h := devd.RouteHandler(logger, r, templates)
	ht := handlerTester{t, h}

	AssertCode(t, ht.Request("GET", "/", nil), 200)
}
开发者ID:justinyaoqi,项目名称:devd,代码行数:12,代码来源:cli_test.go

示例10: ServeFile

// ServeFile replies to the request with the contents of the named file or directory.
func ServeFile(w http.ResponseWriter, r *http.Request, name string) {
	dir, file := filepath.Split(name)
	logger := termlog.NewLog()
	logger.Quiet()

	fs := FileServer{
		"version",
		http.Dir(dir),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
		[]routespec.RouteSpec{},
		"",
	}
	fs.serveFile(logger, w, r, file, false)
}
开发者ID:cortesi,项目名称:devd,代码行数:16,代码来源:fileserver_test.go

示例11: TestDevdHandler

func TestDevdHandler(t *testing.T) {
	logger := termlog.NewLog()
	logger.Quiet()
	templates := ricetemp.MustMakeTemplates(rice.MustFindBox("templates"))

	devd := Devd{LivereloadRoutes: true, WatchPaths: []string{"./"}}
	devd.AddRoutes([]string{"./"})
	h, err := devd.Handler(logger, templates)
	if err != nil {
		t.Error(err)
	}
	ht := handlerTester{t, h}

	AssertCode(t, ht.Request("GET", "/", nil), 200)
	AssertCode(t, ht.Request("GET", "/nonexistent", nil), 404)
}
开发者ID:justinyaoqi,项目名称:devd,代码行数:16,代码来源:cli_test.go

示例12: TestFileServerImplicitLeadingSlash

func TestFileServerImplicitLeadingSlash(t *testing.T) {
	defer afterTest(t)
	tempDir, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatalf("TempDir: %v", err)
	}
	defer mustRemoveAll(tempDir)
	if err := ioutil.WriteFile(filepath.Join(tempDir, "foo.txt"), []byte("Hello world"), 0644); err != nil {
		t.Fatalf("WriteFile: %v", err)
	}
	fs := &FileServer{
		"version",
		http.Dir(tempDir),
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
		[]routespec.RouteSpec{},
		"",
	}

	ts := httptest.NewServer(http.StripPrefix("/bar/", fs))
	defer ts.Close()
	get := func(suffix string) string {
		res, err := http.Get(ts.URL + suffix)
		if err != nil {
			t.Fatalf("Get %s: %v", suffix, err)
		}
		b, err := ioutil.ReadAll(res.Body)
		if err != nil {
			t.Fatalf("ReadAll %s: %v", suffix, err)
		}
		_ = res.Body.Close()
		return string(b)
	}
	if s := get("/bar/"); !strings.Contains(s, ">foo.txt<") {
		t.Logf("expected a directory listing with foo.txt, got %q", s)
	}
	if s := get("/bar/foo.txt"); s != "Hello world" {
		t.Logf("expected %q, got %q", "Hello world", s)
	}
}
开发者ID:cortesi,项目名称:devd,代码行数:40,代码来源:fileserver_test.go

示例13: TestDirectoryIfNotModified

func TestDirectoryIfNotModified(t *testing.T) {
	defer afterTest(t)
	const indexContents = "I am a fake index.html file"
	fileMod := time.Unix(1000000000, 0).UTC()
	fileModStr := fileMod.Format(http.TimeFormat)
	dirMod := time.Unix(123, 0).UTC()
	indexFile := &fakeFileInfo{
		basename: "index.html",
		modtime:  fileMod,
		contents: indexContents,
	}
	fsys := fakeFS{
		"/": &fakeFileInfo{
			dir:     true,
			modtime: dirMod,
			ents:    []*fakeFileInfo{indexFile},
		},
		"/index.html": indexFile,
	}

	fs := &FileServer{
		fsys,
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
	}

	ts := httptest.NewServer(fs)
	defer ts.Close()

	res, err := http.Get(ts.URL)
	if err != nil {
		t.Fatal(err)
	}
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		t.Fatal(err)
	}
	if string(b) != indexContents {
		t.Fatalf("Got body %q; want %q", b, indexContents)
	}
	res.Body.Close()

	lastMod := res.Header.Get("Last-Modified")
	if lastMod != fileModStr {
		t.Fatalf("initial Last-Modified = %q; want %q", lastMod, fileModStr)
	}

	req, _ := http.NewRequest("GET", ts.URL, nil)
	req.Header.Set("If-Modified-Since", lastMod)

	res, err = http.DefaultClient.Do(req)
	if err != nil {
		t.Fatal(err)
	}
	if res.StatusCode != 304 {
		t.Fatalf("Code after If-Modified-Since request = %v; want 304", res.StatusCode)
	}
	res.Body.Close()

	// Advance the index.html file's modtime, but not the directory's.
	indexFile.modtime = indexFile.modtime.Add(1 * time.Hour)

	res, err = http.DefaultClient.Do(req)
	if err != nil {
		t.Fatal(err)
	}
	if res.StatusCode != 200 {
		t.Fatalf("Code after second If-Modified-Since request = %v; want 200; res is %#v", res.StatusCode, res)
	}
	res.Body.Close()
}
开发者ID:homburg,项目名称:devd,代码行数:71,代码来源:fileserver_test.go

示例14: main


//.........这里部分代码省略.........
		logger.Enable("debug")
	}
	if *enableTimer {
		logger.Enable("timer")
	}
	if *throttleDownKbps == 0 {
		*throttleDownKbps = slowdown.MaxRate
	}
	if *throttleUpKbps == 0 {
		*throttleUpKbps = slowdown.MaxRate
	}

	if *allInterfaces {
		*httpIP = "0.0.0.0"
	}

	tlsEnabled := false
	if *certFile != "" {
		tlsEnabled = true
	}

	var hl net.Listener
	var err error
	if *httpPort > 0 {
		hl, err = net.Listen("tcp", fmt.Sprintf("%v:%d", *httpIP, *httpPort))
	} else {
		hl, err = pickPort(*httpIP, portLow, portHigh, tlsEnabled)
	}
	if err != nil {
		kingpin.Fatalf("Could not bind to port: %s", err)
		return
	}

	templates := ricetemp.MustMakeTemplates(rice.MustFindBox("templates"))
	if err != nil {
		kingpin.Fatalf("Error loading templates: %s", err)
		return
	}

	ignores := make([]*regexp.Regexp, 0, 0)
	for _, expr := range *ignoreHeaders {
		v, err := regexp.Compile(expr)
		if err != nil {
			kingpin.Fatalf("%s", err)
		}
		ignores = append(ignores, v)
	}

	routeColl := make(routeCollection)
	for _, s := range *routes {
		err := routeColl.Set(s)
		if err != nil {
			kingpin.FatalUsage("Invalid route specification: %s", err)
		}
	}

	mux := http.NewServeMux()
	var livereloadEnabled = false
	if *livereloadRoutes || len(*watch) > 0 {
		livereloadEnabled = true
	}

	for match, route := range routeColl {
		handler := devdHandler(
			logger,
			route,
开发者ID:mikesavior,项目名称:devd,代码行数:67,代码来源:devd.go

示例15: TestNotFoundOverride

func TestNotFoundOverride(t *testing.T) {
	defer afterTest(t)
	ffile := &fakeFileInfo{
		basename: "foo.html",
		modtime:  time.Unix(1000000000, 0).UTC(),
		contents: "I am a fake file",
	}
	fsys := fakeFS{
		"/": &fakeFileInfo{
			dir:     true,
			modtime: time.Unix(123, 0).UTC(),
			ents:    []*fakeFileInfo{},
		},
		"/one": &fakeFileInfo{
			dir:     true,
			modtime: time.Unix(123, 0).UTC(),
			ents:    []*fakeFileInfo{ffile},
		},
		"/one/foo.html": ffile,
	}

	fs := &FileServer{
		"version",
		fsys,
		inject.CopyInject{},
		ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
		[]routespec.RouteSpec{
			{Host: "", Path: "/", Value: "foo.html"},
		},
		"",
	}

	ts := httptest.NewServer(fs)
	defer ts.Close()

	res, err := http.Get(ts.URL + "/one/nonexistent.html")
	if err != nil {
		t.Fatal(err)
	}
	_ = res.Body.Close()
	if res.StatusCode != 200 {
		t.Error("Expected to find over-ride file.")
	}

	res, err = http.Get(ts.URL + "/one/two/nonexistent.html")
	if err != nil {
		t.Fatal(err)
	}
	_ = res.Body.Close()
	if res.StatusCode != 200 {
		t.Error("Expected to find over-ride file.")
	}

	res, err = http.Get(ts.URL + "/nonexistent.html")
	if err != nil {
		t.Fatal(err)
	}
	_ = res.Body.Close()
	if res.StatusCode != 404 {
		t.Error("Expected to find over-ride file.")
	}

	res, err = http.Get(ts.URL + "/two/nonexistent.html")
	if err != nil {
		t.Fatal(err)
	}
	_ = res.Body.Close()
	if res.StatusCode != 404 {
		t.Error("Expected to find over-ride file.")
	}

}
开发者ID:cortesi,项目名称:devd,代码行数:72,代码来源:fileserver_test.go


注:本文中的github.com/cortesi/devd/ricetemp.MustMakeTemplates函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。