本文整理汇总了Golang中github.com/Unknwon/macaron.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: middlewareScenario
func middlewareScenario(desc string, fn scenarioFunc) {
Convey(desc, func() {
defer bus.ClearBusHandlers()
sc := &scenarioContext{}
viewsPath, _ := filepath.Abs("../../public/views")
sc.m = macaron.New()
sc.m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: viewsPath,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
sc.m.Use(GetContextHandler())
// mock out gc goroutine
startSessionGC = func() {}
sc.m.Use(Sessioner(&session.Options{}))
sc.defaultHandler = func(c *Context) {
sc.context = c
if sc.handlerFunc != nil {
sc.handlerFunc(sc.context)
}
}
sc.m.Get("/", sc.defaultHandler)
fn(sc)
})
}
开发者ID:Cepave,项目名称:grafana,代码行数:30,代码来源:middleware_test.go
示例2: Test_Flash
func Test_Flash(t *testing.T) {
Convey("Test flash", t, func() {
m := macaron.New()
m.Use(Sessioner())
m.Get("/set", func(f *Flash) string {
f.Success("success")
f.Error("error")
f.Warning("warning")
f.Info("info")
return ""
})
m.Get("/get", func() {})
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/set", nil)
So(err, ShouldBeNil)
m.ServeHTTP(resp, req)
resp = httptest.NewRecorder()
req, err = http.NewRequest("GET", "/get", nil)
So(err, ShouldBeNil)
req.Header.Set("Cookie", "macaron_flash=error%3Derror%26info%3Dinfo%26success%3Dsuccess%26warning%3Dwarning; Path=/")
m.ServeHTTP(resp, req)
})
}
开发者ID:mbrukman,项目名称:grafana,代码行数:25,代码来源:session_test.go
示例3: Test_SelectiveRouter
func Test_SelectiveRouter(t *testing.T) {
for _, test := range tests {
w := httptest.NewRecorder()
m := macaron.New()
done := make(chan bool)
selectRoute(m, test.ExpectedMethod, func(rq *http.Request) {
done <- true
})
req, err := http.NewRequest(test.Method, "/", nil)
if err != nil {
t.Fatal(err)
}
OverrideRequestMethod(req, test.OverrideMethod)
m.Before(Override())
go m.ServeHTTP(w, req)
select {
case <-done:
case <-time.After(30 * time.Millisecond):
t.Errorf("Expected router to route to %s, got something else (%v).", test.ExpectedMethod, test)
}
}
}
开发者ID:macaron-contrib,项目名称:method,代码行数:25,代码来源:override_test.go
示例4: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
mapStatic(m, "", "public")
mapStatic(m, "app", "app")
mapStatic(m, "css", "css")
mapStatic(m, "img", "img")
mapStatic(m, "fonts", "fonts")
mapStatic(m, "robots.txt", "robots.txt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}
开发者ID:toni-moreno,项目名称:grafana,代码行数:33,代码来源:web.go
示例5: Test_GenerateToken
func Test_GenerateToken(t *testing.T) {
Convey("Generate token", t, func() {
m := macaron.New()
m.Use(session.Sessioner())
m.Use(Csrfer())
// Simulate login.
m.Get("/login", func(sess session.Store, x CSRF) {
sess.Set("uid", "123456")
})
// Generate token.
m.Get("/private", func() {})
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/login", nil)
So(err, ShouldBeNil)
m.ServeHTTP(resp, req)
cookie := resp.Header().Get("Set-Cookie")
resp = httptest.NewRecorder()
req, err = http.NewRequest("GET", "/private", nil)
So(err, ShouldBeNil)
req.Header.Set("Cookie", cookie)
m.ServeHTTP(resp, req)
})
}
开发者ID:macaron-contrib,项目名称:csrf,代码行数:29,代码来源:csrf_test.go
示例6: main
func main() {
log.Info("Peach %s", APP_VER)
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
m.Use(macaron.Statics(macaron.StaticOptions{
SkipLogging: setting.ProdMode,
}, "custom/public", "public"))
m.Use(i18n.I18n(i18n.Options{
Files: setting.Docs.Locales,
}))
tplDir := "templates"
if setting.Page.UseCustomTpl {
tplDir = "custom/templates"
}
m.Use(pongo2.Pongoer(pongo2.Options{
Directory: tplDir,
}))
m.Use(middleware.Contexter())
m.Get("/", routers.Home)
m.Get("/docs", routers.Docs)
m.Get("/docs/images/*", routers.DocsStatic)
m.Get("/docs/*", routers.Docs)
m.Post("/hook", routers.Hook)
m.Get("/search", routers.Search)
m.Get("/*", routers.Pages)
m.NotFound(routers.NotFound)
listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HTTPPort)
log.Info("%s Listen on %s", setting.Site.Name, listenAddr)
log.Fatal("Fail to start Peach: %v", http.ListenAndServe(listenAddr, m))
}
开发者ID:0-T-0,项目名称:peach,代码行数:35,代码来源:peach.go
示例7: newInstance
func newInstance() *macaron.Macaron {
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
m.Use(macaron.Static("static"))
m.Use(pongo2.Pongoer(pongo2.Options{
Directory: "views",
IndentJSON: macaron.Env != macaron.PROD,
IndentXML: macaron.Env != macaron.PROD,
}))
m.Use(cache.Cacher())
m.Use(session.Sessioner())
//DoXXX 表示GET请求;
//OnXXX 表示POST请求;
//AnyXXX 表示GET、POST混合请求
m.Any("/", AnyValidate)
m.Get("/dogs", DoDogs)
m.Get("/pups", DoPups)
m.Get("/about", DoAbout)
m.Get("/comment", DoComment)
m.Get("/signin", DoSignin)
m.Get("/dogDetail", DoDogDetail)
m.Get("/pupDetail", DoPupDetail)
m.Post("/onComment", OnComment)
m.Post("/onSignin", OnSignin)
return m
}
开发者ID:zileyuan,项目名称:hidog,代码行数:30,代码来源:main.go
示例8: newMacaron
// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(macaron.Gziper())
}
m.Use(macaron.Static(
path.Join(setting.StaticRootPath, "public"),
macaron.StaticOptions{
SkipLogging: !setting.DisableRouterLog,
},
))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "templates"),
Funcs: []template.FuncMap{base.TemplateFuncs},
IndentJSON: macaron.Env != macaron.PROD,
}))
m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubUrl,
Directory: path.Join(setting.ConfRootPath, "locale"),
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs,
Names: setting.Names,
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
Interval: setting.CacheInternal,
Conn: setting.CacheConn,
}))
m.Use(captcha.Captchaer(captcha.Options{
SubURL: setting.AppSubUrl,
}))
m.Use(session.Sessioner(session.Options{
Provider: setting.SessionProvider,
Config: *setting.SessionConfig,
}))
m.Use(csrf.Generate(csrf.Options{
Secret: setting.SecretKey,
SetCookie: true,
Header: "X-Csrf-Token",
CookiePath: setting.AppSubUrl,
}))
m.Use(toolbox.Toolboxer(m, toolbox.Options{
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
&toolbox.HealthCheckFuncDesc{
Desc: "Database connection",
Func: models.Ping,
},
},
}))
m.Use(middleware.Contexter())
return m
}
开发者ID:ericcapricorn,项目名称:gogs,代码行数:56,代码来源:web.go
示例9: runWeb
func runWeb(c *cli.Context) {
m := macaron.New()
web.SetOCTMacaron(m)
listenaddr := fmt.Sprintf("%s:%d", c.String("address"), c.Int("port"))
fmt.Println("Start to listen ", listenaddr)
if err := http.ListenAndServe(listenaddr, m); err != nil {
fmt.Printf("start oct http service error: %v", err.Error())
}
}
开发者ID:liangchenye,项目名称:oct-web,代码行数:11,代码来源:web.go
示例10: main
func main() {
m := macaron.New()
m.Map(logger) // 映射全局服务
// 获取全局服务
m.Get("/logger", func(l *log.Logger) {
l.Println("我正在使用全局日志器")
})
m.Run()
}
开发者ID:Zcgong,项目名称:go-rock-libraries-showcases,代码行数:11,代码来源:main1.go
示例11: Test_Cacher
func Test_Cacher(t *testing.T) {
Convey("Use cache middleware", t, func() {
m := macaron.New()
m.Use(Cacher())
m.Get("/", func() {})
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
m.ServeHTTP(resp, req)
})
Convey("Register invalid adapter", t, func() {
Convey("Adatper not exists", func() {
defer func() {
So(recover(), ShouldNotBeNil)
}()
m := macaron.New()
m.Use(Cacher(Options{
Adapter: "fake",
}))
})
Convey("Provider value is nil", func() {
defer func() {
So(recover(), ShouldNotBeNil)
}()
Register("fake", nil)
})
Convey("Register twice", func() {
defer func() {
So(recover(), ShouldNotBeNil)
}()
Register("memory", &MemoryCacher{})
})
})
}
开发者ID:kolonse,项目名称:cache,代码行数:41,代码来源:cache_test.go
示例12: main
func main() {
m := macaron.New()
m.Get("/", myLogger, func(l *log.Logger) {
l.Println("这是默认日志器")
})
// 获取请求级别服务
m.Get("/logger", myLogger, func(l Logger) {
l.Println("我正在使用全局日志器")
})
m.Run()
}
开发者ID:Zcgong,项目名称:go-rock-libraries-showcases,代码行数:14,代码来源:main3.go
示例13: Test_Captcha
func Test_Captcha(t *testing.T) {
Convey("Captch service", t, func() {
m := macaron.New()
m.Use(cache.Cacher())
m.Use(Captchaer())
m.Get("/", func() {
})
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
m.ServeHTTP(resp, req)
})
}
开发者ID:macaron-contrib,项目名称:captcha,代码行数:15,代码来源:captcha_test.go
示例14: newMacaron
func newMacaron() *macaron.Macaron {
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
m.Use(macaron.Static("static"))
m.Use(session.Sessioner(session.Options{
Provider: "mysql",
ProviderConfig: beego.AppConfig.String("mysqlstring"),
}))
m.Use(middleware.Contexter())
m.Use(pongo2.Pongoer(pongo2.Options{
Directory: "views",
}))
return m
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:16,代码来源:main.go
示例15: runWeb
func runWeb(c *cli.Context) {
m := macaron.New()
if err := db.InitDB(setting.DBURI, setting.DBPasswd, setting.DBDB); err != nil {
fmt.Printf("Connect Database Error %s", err.Error())
}
web.SetWharfMacaron(m)
dockyard.SetDockyardMacaron(m)
crew.SetCrewMacaron(m)
generator.SetGeneratorMacaron(m)
switch setting.ListenMode {
case "http":
listenaddr := fmt.Sprintf("%s:%d", c.String("address"), c.Int("port"))
if err := http.ListenAndServe(listenaddr, m); err != nil {
fmt.Printf("start wharf http service error: %v", err.Error())
}
break
case "https":
listenaddr := fmt.Sprintf("%s:443", c.String("address"))
server := &http.Server{Addr: listenaddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m}
if err := server.ListenAndServeTLS(setting.HttpsCertFile, setting.HttpsKeyFile); err != nil {
fmt.Printf("start wharf https service error: %v", err.Error())
}
break
case "unix":
listenaddr := fmt.Sprintf("%s", c.String("address"))
if utils.IsFileExist(listenaddr) {
os.Remove(listenaddr)
}
if listener, err := net.Listen("unix", listenaddr); err != nil {
fmt.Printf("start wharf unix socket error: %v", err.Error())
} else {
server := &http.Server{Handler: m}
if err := server.Serve(listener); err != nil {
fmt.Printf("start wharf unix socket error: %v", err.Error())
}
}
break
default:
break
}
}
开发者ID:pombredanne,项目名称:wharf-1,代码行数:45,代码来源:web.go
示例16: loadMacaronSingle
func loadMacaronSingle(method, path string, handler interface{}) http.Handler {
m := macaron.New()
switch method {
case "GET":
m.Get(path, handler)
case "POST":
m.Post(path, handler)
case "PUT":
m.Put(path, handler)
case "PATCH":
m.Patch(path, handler)
case "DELETE":
m.Delete(path, handler)
default:
panic("Unknow HTTP method: " + method)
}
return m
}
开发者ID:naoina,项目名称:go-http-routing-benchmark,代码行数:18,代码来源:routers.go
示例17: loadMacaron
func loadMacaron(routes []route) http.Handler {
m := macaron.New()
for _, route := range routes {
switch route.method {
case "GET":
m.Get(route.path, martiniHandler)
case "POST":
m.Post(route.path, martiniHandler)
case "PUT":
m.Put(route.path, martiniHandler)
case "PATCH":
m.Patch(route.path, martiniHandler)
case "DELETE":
m.Delete(route.path, martiniHandler)
default:
panic("Unknow HTTP method: " + route.method)
}
}
return m
}
开发者ID:naoina,项目名称:go-http-routing-benchmark,代码行数:20,代码来源:routers.go
示例18: runWeb
func runWeb(c *cli.Context) {
m := macaron.New()
//Set Macaron Web Middleware And Routers
web.SetDockyardMacaron(m)
switch setting.ListenMode {
case "http":
listenaddr := fmt.Sprintf("%s:%d", c.String("address"), c.Int("port"))
if err := http.ListenAndServe(listenaddr, m); err != nil {
fmt.Printf("启动 dockyard 的 HTTP 服务错误: %v", err)
}
break
case "https":
//HTTPS 强制使用 443 端口
listenaddr := fmt.Sprintf("%s:443", c.String("address"))
server := &http.Server{Addr: listenaddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m}
if err := server.ListenAndServeTLS(setting.HttpsCertFile, setting.HttpsKeyFile); err != nil {
fmt.Printf("启动 dockyard 的 HTTPS 服务错误: %v", err)
}
break
case "unix":
listenaddr := fmt.Sprintf("%s", c.String("address"))
//如果存在 Unix Socket 文件就删除
if utils.Exist(listenaddr) {
os.Remove(listenaddr)
}
if listener, err := net.Listen("unix", listenaddr); err != nil {
fmt.Printf("启动 dockyard 的 Unix Socket 监听错误: %v", err)
} else {
server := &http.Server{Handler: m}
if err := server.Serve(listener); err != nil {
fmt.Printf("启动 dockyard 的 Unix Socket 监听错误: %v", err)
}
}
break
default:
break
}
}
开发者ID:rechen,项目名称:dockyard,代码行数:41,代码来源:web.go
示例19: Test_ParamenterOverride
func Test_ParamenterOverride(t *testing.T) {
for _, test := range tests {
w := httptest.NewRecorder()
m := macaron.New()
m.Before(Override())
m.Use(func(w http.ResponseWriter, r *http.Request) {
if r.Method != test.ExpectedMethod {
t.Errorf("Expected %s, got %s", test.ExpectedMethod, r.Method)
}
})
query := "_method=" + test.OverrideMethod
r, err := http.NewRequest(test.Method, "/?"+query, nil)
if err != nil {
t.Fatal(err)
}
m.ServeHTTP(w, r)
}
}
开发者ID:macaron-contrib,项目名称:method,代码行数:21,代码来源:override_test.go
示例20: Test_In
func Test_In(t *testing.T) {
for _, test := range tests {
w := httptest.NewRecorder()
m := macaron.New()
m.Before(Override())
m.Use(func(w http.ResponseWriter, r *http.Request) {
if r.Method != test.ExpectedMethod {
t.Errorf("Expected %s, got %s", test.ExpectedMethod, r.Method)
}
})
r, err := http.NewRequest(test.Method, "/", nil)
if err != nil {
t.Fatal(err)
}
OverrideRequestMethod(r, test.OverrideMethod)
m.ServeHTTP(w, r)
}
}
开发者ID:macaron-contrib,项目名称:method,代码行数:21,代码来源:override_test.go
注:本文中的github.com/Unknwon/macaron.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论