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


Golang engine.Request类代码示例

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


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

示例1: ServeHTTP

func (e *Echo) ServeHTTP(req engine.Request, res engine.Response) {
	c := e.pool.Get().(*context)
	c.Reset(req, res)

	// Middleware
	h := func(Context) error {
		method := req.Method()
		path := req.URL().Path()
		e.router.Find(method, path, c)
		h := c.handler
		for i := len(e.middleware) - 1; i >= 0; i-- {
			h = e.middleware[i](h)
		}
		return h(c)
	}

	// Premiddleware
	for i := len(e.premiddleware) - 1; i >= 0; i-- {
		h = e.premiddleware[i](h)
	}

	// Execute chain
	if err := h(c); err != nil {
		e.httpErrorHandler(err, c)
	}

	e.pool.Put(c)
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:28,代码来源:echo.go

示例2: getIPFromRequest

func getIPFromRequest(r engine.Request) string {
	if ipProxy := r.Header().Get("X-FORWARDED-FOR"); len(ipProxy) > 0 {
		return ipProxy
	}
	ip, _, _ := net.SplitHostPort(r.RemoteAddress())
	return ip
}
开发者ID:golang-devops,项目名称:go-psexec,代码行数:7,代码来源:util.go

示例3: manageAnalytics

func (ws *WebService) manageAnalytics(url *storage.URL, request engine.Request, longURL bool, shortURL bool) {
	log.Printf("[INFO] [abraracourcix] Analytics for URL : %v %s %s",
		url, request.UserAgent(), request.RemoteAddress())
	key := storage.GetAnalyticsKey(url.Key)
	stat, err := ws.retrieveAnalytics([]byte(key))
	if err != nil {
		log.Printf("[WARN] [abraracourcix] Can't decode Analytics %v", err)
		return
	}
	log.Printf("[INFO] [abraracourcix] Analytics find : %v", stat)
	ua := request.UserAgent()
	if stat.UserAgents != nil {
		stat.UserAgents[ua] = stat.UserAgents[ua] + 1
	} else {
		stat.UserAgents = make(map[string]int64)
		stat.UserAgents[ua] = 1
	}
	if longURL {
		stat.LongURLClicks = stat.LongURLClicks + 1
	}
	if shortURL {
		stat.ShortURLClicks = stat.ShortURLClicks + 1
	}
	err = ws.storeAnalytics([]byte(key), stat)
	if err != nil {
		log.Printf("[WARN] [abraracourcix] Can't store analytics URL %s %v",
			url, stat)
	}
	log.Printf("[INFO] [abraracourcix] Analytics updated : %v", stat)
}
开发者ID:nlamirault,项目名称:abraracourcix,代码行数:30,代码来源:webservice.go

示例4: RequestTest

func RequestTest(t *testing.T, request engine.Request) {
	assert.Equal(t, "github.com", request.Host())

	request.SetURI("/labstack/echo?token=54321")
	assert.Equal(t, "/labstack/echo?token=54321", request.URI())

	assert.Equal(t, "/labstack/echo", request.URL().Path())
	assert.Equal(t, "https://github.com/", request.Referer())
	assert.Equal(t, "127.0.0.1", request.Header().Get("X-Real-IP"))
	assert.Equal(t, "https", request.Scheme())
	assert.Equal(t, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10", request.UserAgent())
	assert.Equal(t, "127.0.0.1", request.RemoteAddress())
	assert.Equal(t, "POST", request.Method())

	assert.Equal(t, int64(261), request.ContentLength())
	assert.Equal(t, "bar", request.FormValue("foo"))

	if fHeader, err := request.FormFile("note"); assert.NoError(t, err) {
		if file, err := fHeader.Open(); assert.NoError(t, err) {
			text, _ := ioutil.ReadAll(file)
			assert.Equal(t, "Hello world!", string(text))
		}
	}

	assert.Equal(t, map[string][]string{"baz": []string{"bat"}, "foo": []string{"bar"}}, request.FormParams())

	if form, err := request.MultipartForm(); assert.NoError(t, err) {
		_, ok := form.File["note"]
		assert.True(t, ok)
	}

	request.SetMethod("PUT")
	assert.Equal(t, "PUT", request.Method())

	request.SetBody(strings.NewReader("Hello"))
	if body, err := ioutil.ReadAll(request.Body()); assert.NoError(t, err) {
		assert.Equal(t, "Hello", string(body))
	}

	if cookie, err := request.Cookie("session"); assert.NoError(t, err) {
		assert.Equal(t, "session", cookie.Name())
		assert.Equal(t, "securetoken", cookie.Value())
	}

	_, err := request.Cookie("foo")
	assert.Error(t, err)

	assert.Equal(t, 2, len(request.Cookies()))
}
开发者ID:eurie-inc,项目名称:echo-sample,代码行数:49,代码来源:test_request.go


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