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

Golang ace.New函数代码示例

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

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



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

示例1: loadAce

func loadAce(routes []route) http.Handler {
	router := ace.New()
	for _, route := range routes {
		router.Handle(route.method, route.path, []ace.HandlerFunc{aceHandle})
	}
	return router
}
开发者ID:naoina,项目名称:go-http-routing-benchmark,代码行数:7,代码来源:routers.go


示例2: main

func main() {
	a := ace.New()
	a.Use(gzip.Gzip(gzip.DefaultCompression))
	a.GET("/ping", func(c *ace.C) {
		c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
	})

	// Listen and Server in 0.0.0.0:8080
	a.Run(":8080")
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:10,代码来源:example.go


示例3: newServer

func newServer(useGzip bool) *ace.ace {
	r := ace.New()
	if useGzip {
		r.Use(Gzip(DefaultCompression))
	}
	r.GET("/", func(c *ace.C) {
		c.Writer.Header().Set(headerContentLength, strconv.Itoa(len(testResponse)))
		c.String(200, testResponse)
	})
	return r
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:11,代码来源:gzip_test.go


示例4: TestRequestMethod

func TestRequestMethod(t *testing.T) {
	g := ace.New()
	g.Use(Cors(Options{
		AllowMethods: []string{},
	}))
	assert := assert.New(t)

	r := request(g, requestOptions{
		Method: "OPTIONS",
		URL:    "/",
		Headers: map[string]string{
			"Origin":                        "http://maji.moe",
			"Access-Control-Request-Method": "PUT",
		},
	})

	assert.Equal("", r.Header().Get("Access-Control-Allow-Methods"))
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:18,代码来源:cors_test.go


示例5: TestCSRFForm

func TestCSRFForm(t *testing.T) {
	assert := assert.New(t)

	token := ""

	a := ace.New()
	a.Session(cookie.NewCookieStore(), nil)
	CSRF(nil)

	a.GET("/", func(c *ace.C) {
		token = Token(c)
		c.JSON(200, nil)
	})

	a.POST("/", Validate, func(c *ace.C) {
		c.String(200, "passed")
	})

	r, _ := http.NewRequest("GET", "/", nil)
	w := httptest.NewRecorder()
	a.ServeHTTP(w, r)
	assert.NotEmpty(token)

	cookie := w.Header().Get("Set-Cookie")
	r, _ = http.NewRequest("POST", "/", nil)
	r.Header.Set("Cookie", cookie)
	r.ParseForm()
	r.PostForm.Set("csrf_token", token)
	w = httptest.NewRecorder()
	a.ServeHTTP(w, r)
	assert.Equal(200, w.Code)
	assert.Equal("passed", w.Body.String())

	cookie = w.Header().Get("Set-Cookie")
	r, _ = http.NewRequest("POST", "/", nil)
	r.Header.Set("Cookie", cookie)
	r.ParseForm()
	r.PostForm.Set("csrf_token", token)
	w = httptest.NewRecorder()
	a.ServeHTTP(w, r)
	assert.Equal(500, w.Code)
	assert.Equal("Invalid CSRF Token", w.Body.String())
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:43,代码来源:csrf_test.go


示例6: TestMaxAge

func TestMaxAge(t *testing.T) {
	g := ace.New()
	g.Use(Cors(Options{
		MaxAge: time.Hour,
	}))
	assert := assert.New(t)
	g.OPTIONS("/", func(c *ace.C) {
		c.String(http.StatusOK, "")
	})

	r := request(g, requestOptions{
		Method: "OPTIONS",
		URL:    "/",
		Headers: map[string]string{
			"Origin": "http://maji.moe",
		},
	})

	assert.Equal("3600", r.Header().Get("Access-Control-Max-Age"))
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:20,代码来源:cors_test.go


示例7: TestAllowHeaders

func TestAllowHeaders(t *testing.T) {
	g := ace.New()
	g.Use(Cors(Options{
		AllowHeaders: []string{"X-Custom-Header", "X-Auth-Token"},
	}))
	assert := assert.New(t)
	g.OPTIONS("/", func(c *ace.C) {
		c.String(http.StatusOK, "")
	})

	r := request(g, requestOptions{
		Method: "OPTIONS",
		URL:    "/",
		Headers: map[string]string{
			"Origin": "http://maji.moe",
		},
	})

	assert.Equal("X-Custom-Header,X-Auth-Token", r.Header().Get("Access-Control-Allow-Headers"))
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:20,代码来源:cors_test.go


示例8: TestAllowCredentials

func TestAllowCredentials(t *testing.T) {
	g := ace.New()
	g.Use(Cors(Options{
		AllowCredentials: true,
	}))
	assert := assert.New(t)

	g.GET("/test", func(c *ace.C) {
		c.String(http.StatusOK, "OK")
	})

	r := request(g, requestOptions{
		URL: "/test",
		Headers: map[string]string{
			"Origin": "http://maji.moe",
		},
	})

	assert.Equal("true", r.Header().Get("Access-Control-Allow-Credentials"))
	assert.Equal("OK", r.Body.String())
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:21,代码来源:cors_test.go


示例9: TestAllowMethods

func TestAllowMethods(t *testing.T) {
	g := ace.New()
	g.Use(Cors(Options{
		AllowMethods: []string{"GET", "POST", "PUT"},
	}))
	g.OPTIONS("/", func(c *ace.C) {
		c.String(http.StatusOK, "")
	})

	assert := assert.New(t)

	r := request(g, requestOptions{
		Method: "OPTIONS",
		URL:    "/",
		Headers: map[string]string{
			"Origin": "http://maji.moe",
		},
	})

	assert.Equal("GET,POST,PUT", r.Header().Get("Access-Control-Allow-Methods"))
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:21,代码来源:cors_test.go


示例10: TestExposeHeaders

func TestExposeHeaders(t *testing.T) {
	g := ace.New()
	g.Use(Cors(Options{
		ExposeHeaders: []string{"Foo", "Bar"},
	}))
	assert := assert.New(t)

	g.GET("/test", func(c *ace.C) {
		c.String(http.StatusOK, "OK")
	})

	r := request(g, requestOptions{
		URL: "/test",
		Headers: map[string]string{
			"Origin": "http://maji.moe",
		},
	})

	assert.Equal("Foo,Bar", r.Header().Get("Access-Control-Expose-Headers"))
	assert.Equal("OK", r.Body.String())
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:21,代码来源:cors_test.go


示例11: startAce

func startAce() {
	mux := ace.New()
	mux.GET("/hello", aceHandler)
	mux.Run(":" + strconv.Itoa(port))
}
开发者ID:cokeboL,项目名称:go-web-framework-benchmark,代码行数:5,代码来源:server.go


示例12: newServer

func newServer() *ace.Ace {
	g := ace.New()
	g.Use(Cors(Options{}))

	return g
}
开发者ID:sbusso,项目名称:ace-contrib,代码行数:6,代码来源:cors_test.go


示例13: loadAceSingle

func loadAceSingle(method, path string, handle ace.HandlerFunc) http.Handler {
	router := ace.New()
	router.Handle(method, path, []ace.HandlerFunc{handle})
	return router
}
开发者ID:naoina,项目名称:go-http-routing-benchmark,代码行数:5,代码来源:routers.go


示例14: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	app := cli.NewApp()
	app.Name = "Ivy"
	app.Usage = "Assets & Image processing on the fly"
	app.Author = "Witoo Harianto"
	app.Email = "[email protected]"
	app.Version = "1.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "url,u",
			Value: ":4900",
			Usage: "server port",
		},
		cli.IntFlag{
			Name:  "httpcache,t",
			Value: 0,
			Usage: "if cache enable this is http cache in second",
		},
		cli.StringFlag{
			Name:  "cache,c",
			Value: "",
			Usage: "enable cache, specific  eg, file",
		},
		cli.StringFlag{
			Name:  "source,s",
			Value: "file",
			Usage: "source of image eg, file, s3",
		},
		cli.StringFlag{
			Name:   "s3key",
			Value:  "",
			Usage:  "if source is s3, AWS S3 access key",
			EnvVar: "AWS_ACCESS_KEY",
		},
		cli.StringFlag{
			Name:   "s3secret",
			Value:  "",
			Usage:  "if source is s3, AWS S3 secret key",
			EnvVar: "AWS_SECRET_KEY",
		},
		cli.StringFlag{
			Name:  "sourceroot",
			Value: "",
			Usage: "if source is file, specific root path of image",
		},

		cli.StringFlag{
			Name:  "cacheroot",
			Value: "",
			Usage: "if cache is file, specific root path of cache",
		},
	}
	app.Action = func(c *cli.Context) {
		var source ivy.Source
		switch c.String("source") {
		case "s3":
			source = ivy.NewS3Source(c.String("s3key"), c.String("s3secret"))
		default:
			source = ivy.NewFileSystemSource(c.String("sourceroot"))
		}

		var cache ivy.Cache
		switch c.String("cache") {
		case "file":
			cache = ivy.NewFileSystemCache("cacheroot")
		default:
			cache = nil
		}

		iv := ivy.New(source, cache, ivy.NewGMProcessor(), &ivy.Config{
			HTTPCache:     int64(c.Int("httpcache")),
			IsDevelopment: false,
		})

		a := ace.New()

		a.GET("/:bucket/:params/*path", func(c *ace.C) {
			start := stopwatch.Start()
			params, _ := url.QueryUnescape(c.Params.ByName("params"))
			iv.Get(c.Params.ByName("bucket"), params, c.Params.ByName("path"), c.Writer, c.Request)
			watch := stopwatch.Stop(start)
			log.Printf("[Ivy] %d %s %vms", c.Writer.Status(), c.Request.URL.String(), watch.Milliseconds())
		})

		url := c.String("url")
		log.Println("[Ivy] Start server on " + url)
		a.Run(url)
	}

	app.Run(os.Args)
}
开发者ID:maxid,项目名称:ivy,代码行数:92,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang plotbot.Bot类代码示例发布时间:2022-05-28
下一篇:
Golang log.Trace函数代码示例发布时间: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