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


Golang macaron.Classic函数代码示例

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


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

示例1: Test_Render_XHTML

func Test_Render_XHTML(t *testing.T) {
	Convey("Render XHTML", t, func() {
		m := macaron.Classic()
		m.Use(Pongoer(Options{
			Directory:       "fixtures/basic",
			HTMLContentType: ContentXHTML,
		}))
		m.Get("/foobar", func(r macaron.Render) {
			r.HTML(200, "hello", map[string]interface{}{
				"Name": "jeremy",
			})
		})

		resp := httptest.NewRecorder()
		req, err := http.NewRequest("GET", "/foobar", nil)
		So(err, ShouldBeNil)
		m.ServeHTTP(resp, req)

		So(resp.Code, ShouldEqual, http.StatusOK)
		So(resp.Header().Get(ContentType), ShouldEqual, ContentXHTML+"; charset=UTF-8")
		So(resp.Body.String(), ShouldEqual, "<h1>Hello jeremy</h1>")
	})

	m := macaron.Classic()
	m.Use(Pongoer(Options{
		Directory:       "fixtures/basic",
		HTMLContentType: ContentXHTML,
	}))
}
开发者ID:bfloriang,项目名称:dock2box,代码行数:29,代码来源:pongo2_test.go

示例2: performFileTest

func performFileTest(t *testing.T, binder handlerFunc, testCase fileTestCase) {
	httpRecorder := httptest.NewRecorder()
	m := macaron.Classic()

	fileTestHandler := func(actual BlogPost, errs Errors) {
		assertFileAsExpected(t, testCase, actual.HeaderImage, testCase.singleFile)
		So(len(testCase.multipleFiles), ShouldEqual, len(actual.Pictures))

		for i, expectedFile := range testCase.multipleFiles {
			if i >= len(actual.Pictures) {
				break
			}
			assertFileAsExpected(t, testCase, actual.Pictures[i], expectedFile)
		}
	}

	m.Post(testRoute, binder(BlogPost{}), func(actual BlogPost, errs Errors) {
		fileTestHandler(actual, errs)
	})

	m.ServeHTTP(httpRecorder, buildRequestWithFile(testCase))

	switch httpRecorder.Code {
	case http.StatusNotFound:
		panic("Routing is messed up in test fixture (got 404): check methods and paths")
	case http.StatusInternalServerError:
		panic("Something bad happened on '" + testCase.description + "'")
	}
}
开发者ID:mbrukman,项目名称:grafana,代码行数:29,代码来源:file_test.go

示例3: newGitea

func newGitea() *macaron.Macaron {
	m := macaron.Classic()

	m.Use(macaron.Renderer(macaron.RenderOptions{
		Funcs: []template.FuncMap{map[string]interface{}{
			"dict":     base.Dict,
			"str2html": base.Str2html,
			"appVersion": func() string {
				return version
			},
			"appRev": func() string {
				return revision
			},
		}},
	}))

	m.Use(i18n.I18n(i18n.Options{
		Langs:    setting.Langs,
		Names:    setting.Names,
		Redirect: true,
	}))

	m.Get("/", routers.Home)
	m.Get("/docs/images/:all", routers.Static)
	m.Get("/docs", routers.Docs)
	m.Get("/docs/*", routers.Docs)
	m.Get("/about", routers.About)
	m.Get("/team", routers.Team)

	return m
}
开发者ID:joubertredrat,项目名称:website,代码行数:31,代码来源:website.go

示例4: main

func main() {
	m := macaron.Classic()
	m.Get("/", myHandler)

	log.Println("Server is running...")
	log.Println(http.ListenAndServe("0.0.0.0:4000", m))
}
开发者ID:Zcgong,项目名称:go-rock-libraries-showcases,代码行数:7,代码来源:main2.go

示例5: main

func main() {
	// Setup our handler
	m := macaron.Classic()
	m.Get("/", hello)
	m.Get("/enc", Enc)
	m.Get("/dec", Dec)

	m.Get("/vienc", ViEnc)
	m.Get("/videc", ViDec)

	str, e := os.Getwd()
	if e != nil {
		panic(e)
	}
	e = ioutil.WriteFile("logg", []byte(str), 0777)
	if e != nil {
		panic(e)
	}
	// Create a link back to node-webkit using the environment variable
	// populated by golang-nw's node-webkit code
	nodeWebkit, err := nw.New()
	if err != nil {
		panic(err)
	}

	// Pick a random localhost port, start listening for http requests using default handler
	// and send a message back to node-webkit to redirect
	if err := nodeWebkit.ListenAndServe(m); err != nil {
		panic(err)
	}
}
开发者ID:zhuharev,项目名称:vigenere-gui,代码行数:31,代码来源:main.go

示例6: Test_Render_NoRace

func Test_Render_NoRace(t *testing.T) {
	Convey("Make sure render has no race", t, func() {
		m := macaron.Classic()
		m.Use(Pongoer(Options{
			Directory: "fixtures/basic",
		}))
		m.Get("/foobar", func(r macaron.Render) {
			r.HTML(200, "hello", map[string]interface{}{
				"Name": "world",
			})
		})

		done := make(chan bool)
		doreq := func() {
			resp := httptest.NewRecorder()
			req, _ := http.NewRequest("GET", "/foobar", nil)
			m.ServeHTTP(resp, req)
			done <- true
		}
		// Run two requests to check there is no race condition
		go doreq()
		go doreq()
		<-done
		<-done
	})
}
开发者ID:bfloriang,项目名称:dock2box,代码行数:26,代码来源:pongo2_test.go

示例7: main

func main() {
	// flag.Parse()
	log.Info("App Version: %s", APP_VER)
	var port string
	if port = os.Getenv(PortVar); port == "" {
		port = "8080"
	}
	log.Info("PORT: %s", port)

	m := macaron.Classic()
	m.Use(macaron.Renderer())
	// m.Use(middleware.Contexter())

	m.Get("/", func() string {
		return "Hello"
	})
	m.Get("/fibonacci", v1.Fibonacci)

	// log.Info("PORT: %s", setting.HTTPPort)
	// _ = setting.HTTPPort

	http.ListenAndServe(":"+port, m)

	// http.ListenAndServe(fmt.Sprintf(":%d", *port), m)
	// http.ListenAndServe(":"+setting.HTTPPort, m)
	// m.Run(":" + setting.HTTPPort)
}
开发者ID:wangqifox,项目名称:fibonacci,代码行数:27,代码来源:main.go

示例8: main

func main() {
	m := macaron.Classic()
	m.Get("/", func() string {
		return "Hello world!"
	})
	m.Run()
}
开发者ID:Zcgong,项目名称:go-rock-libraries-showcases,代码行数:7,代码来源:main1.go

示例9: Test_Render_Extensions

/*
func Test_Render_Extensions(t *testing.T) {
    m := macaron.Classic()
    m.Use(Renderer(Options{
        Directory:  "fixtures/basic",
        Extensions: []string{".tmpl", ".html"},
    }))

    // routing
    m.Get("/foobar", func(r Render) {
        r.HTML(200, "hypertext", nil)
    })

    res := httptest.NewRecorder()
    req, _ := http.NewRequest("GET", "/foobar", nil)

    m.ServeHTTP(res, req)

    expect(t, res.Code, 200)
    expect(t, res.Header().Get(ContentType), ContentHTML+"; charset=UTF-8")
    expect(t, res.Body.String(), "Hypertext!\n")
}
*/
func Test_Render_Funcs(t *testing.T) {

	m := macaron.Classic()
	m.Use(Renderer(Options{
		Directory: "fixtures/basic",
		Funcs: []template.FuncMap{
			{
				"foo": func() string {
					return "My custom function"
				},
			},
		},
	}))

	// routing
	m.Get("/foobar", func(r Render) {
		r.HTML(200, "custom-func", "jeremy")
	})

	res := httptest.NewRecorder()
	req, _ := http.NewRequest("GET", "/foobar", nil)

	m.ServeHTTP(res, req)

	expect(t, res.Body.String(), "My custom function\n")
}
开发者ID:macaron-contrib,项目名称:jade,代码行数:49,代码来源:render_test.go

示例10: main

func main() {
	// Set log options.
	log.SetOutput(os.Stderr)
	log.SetLevel(log.WarnLevel)

	// Options.
	var opts struct {
		Verbose     bool   `short:"v" long:"verbose" description:"Verbose"`
		Version     bool   `long:"version" description:"Version"`
		BindAddr    string `short:"b" long:"bind-addr" description:"Bind to address" default:"0.0.0.0"`
		Port        int    `short:"p" long:"port" description:"Port" default:"5050"`
		StaticDir   string `short:"s" long:"static-dir" description:"Static content" default:"static"`
		TemplateDir string `short:"t" long:"template-dir" description:"Templates" default:"templates"`
	}

	// Parse options.
	if _, err := flags.Parse(&opts); err != nil {
		ferr := err.(*flags.Error)
		if ferr.Type == flags.ErrHelp {
			os.Exit(0)
		} else {
			log.Fatal(err.Error())
		}
	}

	// Print version.
	if opts.Version {
		fmt.Printf("peekaboo %s\n", Version)
		os.Exit(0)
	}

	// Set verbose.
	if opts.Verbose {
		log.SetLevel(log.InfoLevel)
	}

	// Check root.
	if runtime.GOOS != "darwin" && os.Getuid() != 0 {
		log.Fatal("This application requires root privileges to run.")
	}

	info, err := hwinfo.Get()
	if err != nil {
		log.Fatal(err.Error())
	}

	log.Infof("Using static dir: %s", opts.StaticDir)
	log.Infof("Using template dir: %s", opts.TemplateDir)

	m := macaron.Classic()
	m.Use(macaron.Static(opts.StaticDir))
	m.Use(macaron.Renderer(macaron.RenderOptions{
		Directory:  opts.TemplateDir,
		IndentJSON: true,
	}))

	routes(m, info)
	m.Run(opts.BindAddr, opts.Port)
}
开发者ID:smithjm,项目名称:peekaboo,代码行数:59,代码来源:main.go

示例11: init

func init() {
	m = macaron.Classic()
	m.Use(modules.Public)
	m.Use(modules.Renderer)

	flag.IntVar(&gcfg.port, "port", 8000, "Which port to listen")
	flag.StringVar(&gcfg.root, "root", ".", "Watched root directory for filesystem events, also the HTTP File Server's root directory")
	flag.BoolVar(&gcfg.private, "private", false, "Only listen on lookback interface, otherwise listen on all interface")
}
开发者ID:jameswei,项目名称:file-server,代码行数:9,代码来源:main.go

示例12: main

func main() {
	log.Info("App Version: %s", APP_VER)
	m := macaron.Classic()
	m.Use(macaron.Renderer())
	m.Use(middleware.Contexter())

	m.Get("/fibonacci", v1.Fibonacci)

	m.Run(setting.HTTPPort)
}
开发者ID:mehulsbhatt,项目名称:fws,代码行数:10,代码来源:main.go

示例13: main

func main() {
	server_root := "https://nicksite.com:3000"
	local_login_url := "http://nicksite.com:4000/login"

	m := macaron.Classic()
	m.Use(macaron.Renderer())
	m.Use(session.Sessioner())

	m.Get("/login", func(ctx *macaron.Context, s session.Store) {
		ticket := ctx.Query("ticket")
		if len(ticket) == 0 {
			ctx.Redirect(server_root + "/login?service=" + local_login_url)
			return
		} else {
			s.Set("ticket", ticket)
			ctx.Redirect("/")
		}
	})

	m.Get("/", func(ctx *macaron.Context, s session.Store) string {
		if s.Get("login") != nil {
			return "Welcome, " + s.Get("login").(string)
		}

		// Retrieve the ticket
		if s.Get("ticket") == nil {
			ctx.Redirect("/login")
			return ""
		}

		// Validate the ticket
		ticket := s.Get("ticket").(string)
		resp, err := http.Get(server_root + "/validate?ticket=" + ticket + "&service=" + local_login_url)

		if err != nil {
			log.Fatalf("ERROR: %s\n", err)
			return "Unable to validate the ticket"
		}

		bs, _ := ioutil.ReadAll(resp.Body)
		split := strings.Split(string(bs), "\n")
		ticketValid, login := split[0] == "yes", split[1]

		if ticketValid {
			s.Set("login", login)
			ctx.Redirect("/")
			return ""
		}

		return "Invalid login"
	})

	m.Run()
}
开发者ID:henryluki,项目名称:cas,代码行数:54,代码来源:go_cas_client.go

示例14: Test_Default

func Test_Default(t *testing.T) {
	Convey("Test default value", t, func() {
		m := macaron.Classic()
		m.Get("/", Bind(defaultForm{}), func(f defaultForm) {
			So(f.Default, ShouldEqual, "hello world")
		})
		resp := httptest.NewRecorder()
		req, err := http.NewRequest("GET", "/", nil)
		So(err, ShouldBeNil)

		m.ServeHTTP(resp, req)
	})
}
开发者ID:mbrukman,项目名称:grafana,代码行数:13,代码来源:form_test.go

示例15: main

func main() {
	m := macaron.Classic()
	// render html templates from templates directory
	m.Use(jade.Renderer())

	m.Get("/", func(r jade.Render) {
		r.HTML(200, "hello", map[string]string{
			"foo": "bar",
		})
	})

	m.Run()
}
开发者ID:codeskyblue,项目名称:macaron-jade,代码行数:13,代码来源:main.go


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