• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang macaron.Classic函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: main

func main() {
	m := macaron.Classic()
	m.Use(macaron.Renderer())
	m.Get("/", func(ctx *macaron.Context) {
		ctx.HTML(200, "home")
	})
	m.Get("/ws", func(ctx *macaron.Context) {
		conn, err := upgrader.Upgrade(ctx.Resp, ctx.Req.Request, nil)
		if err != nil {
			log.Printf("Fail to upgrade connection: %v", err)
			return
		}

		stop := make(chan bool)
		for {
			_, data, err := conn.ReadMessage()
			if err != nil {
				if err != io.EOF {
					log.Printf("Fail to read message: %v", err)
				}
				return
			}
			msg := string(data)

			switch msg {
			case "START":
				if len(people) == 0 {
					conn.WriteMessage(websocket.TextMessage, []byte("没人了我会乱说?"))
					conn.Close()
					return
				}
				go sendRandomInfo(conn, stop)
			case "STOP":
				stop <- true
			default:
				// Find corresponding name to display.
				for i, p := range people {
					if p.info == msg {
						if err = conn.WriteMessage(websocket.TextMessage, []byte(p.name)); err != nil {
							log.Printf("Fail to send message: %v", err)
							return
						}
						people = append(people[:i], people[i+1:]...)
					}
				}
			}
		}
	})
	m.Run()
}
开发者ID:xormplus,项目名称:examples,代码行数:50,代码来源:lottery.go


示例17: TestUnallowedMethods

func TestUnallowedMethods(t *testing.T) {
	m := macaron.Classic()

	recorder := httptest.NewRecorder()
	req, err := http.NewRequest("POST", "/test", strings.NewReader(""))

	if err != nil {
		t.Error(err)
	}

	m.Any("/test", Messages(), func() int {
		return http.StatusOK
	})

	m.ServeHTTP(recorder, req)
	expectStatusCode(t, http.StatusMethodNotAllowed, recorder.Code)
}
开发者ID:macaron-contrib,项目名称:sockets,代码行数:17,代码来源:sockets_test.go


示例18: Test_SetWithProperType

// When binding from Form data, testing the type of data to bind
// and converting a string into that type is tedious, so these tests
// cover all those cases.
func Test_SetWithProperType(t *testing.T) {
	Convey("Set with proper type", t, func() {
		testInputs := map[string]string{
			"successful": `integer=-1&integer8=-8&integer16=-16&integer32=-32&integer64=-64&uinteger=1&uinteger8=8&uinteger16=16&uinteger32=32&uinteger64=64&boolean_1=true&fl32_1=32.3232&fl64_1=-64.6464646464&str=string`,
			"errorful":   `integer=&integer8=asdf&integer16=--&integer32=&integer64=dsf&uinteger=&uinteger8=asdf&uinteger16=+&uinteger32= 32 &uinteger64=+%20+&boolean_1=&boolean_2=asdf&fl32_1=asdf&fl32_2=&fl64_1=&fl64_2=asdfstr`,
		}

		expectedOutputs := map[string]Everything{
			"successful": Everything{
				Integer:    -1,
				Integer8:   -8,
				Integer16:  -16,
				Integer32:  -32,
				Integer64:  -64,
				Uinteger:   1,
				Uinteger8:  8,
				Uinteger16: 16,
				Uinteger32: 32,
				Uinteger64: 64,
				Boolean_1:  true,
				Fl32_1:     32.3232,
				Fl64_1:     -64.6464646464,
				Str:        "string",
			},
			"errorful": Everything{},
		}

		for key, testCase := range testInputs {
			httpRecorder := httptest.NewRecorder()
			m := macaron.Classic()

			m.Post(testRoute, Form(Everything{}), func(actual Everything, errs Errors) {
				So(fmt.Sprintf("%+v", actual), ShouldEqual, fmt.Sprintf("%+v", expectedOutputs[key]))
			})
			req, err := http.NewRequest("POST", testRoute, strings.NewReader(testCase))
			if err != nil {
				panic(err)
			}
			req.Header.Set("Content-Type", formContentType)
			m.ServeHTTP(httpRecorder, req)
		}
	})
}
开发者ID:mbrukman,项目名称:grafana,代码行数:46,代码来源:misc_test.go


示例19: Test_Render_Extensions

func Test_Render_Extensions(t *testing.T) {
	Convey("Render with extensions", t, func() {
		m := macaron.Classic()
		m.Use(Pongoer(Options{
			Directory:  "fixtures/basic",
			Extensions: []string{".tmpl", ".html"},
		}))
		m.Get("/foobar", func(r macaron.Render) {
			r.HTML(200, "hypertext", map[string]interface{}{})
		})

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

		So(resp.Body.String(), ShouldEqual, "Hypertext!")
	})
}
开发者ID:bfloriang,项目名称:dock2box,代码行数:19,代码来源:pongo2_test.go


示例20: Test_Render_Bad_HTML

func Test_Render_Bad_HTML(t *testing.T) {
	m := macaron.Classic()
	m.Use(Renderer(Options{
		Directory: "fixtures/basic",
	}))

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

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

	m.ServeHTTP(res, req)

	expect(t, res.Code, 500)
	expect(t, res.Body.String(), "html/template: \"nope\" is undefined\n")
}
开发者ID:macaron-contrib,项目名称:jade,代码行数:19,代码来源:render_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang macaron.Logger函数代码示例发布时间:2022-05-28
下一篇:
Golang log.Info函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap