當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Request.URL方法代碼示例

本文整理匯總了Golang中github.com/labstack/echo/engine.Request.URL方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.URL方法的具體用法?Golang Request.URL怎麽用?Golang Request.URL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/labstack/echo/engine.Request的用法示例。


在下文中一共展示了Request.URL方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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, "http", 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)

	// Cookies
	cs := request.Cookies()
	if assert.Len(t, cs, 2) {
		assert.Equal(t, "session", cs[0].Name())
		assert.Equal(t, "securetoken", cs[0].Value())
		assert.Equal(t, "user", cs[1].Name())
		assert.Equal(t, "123", cs[1].Value())
	}
}
開發者ID:o1egl,項目名稱:echo,代碼行數:56,代碼來源:test_request.go


注:本文中的github.com/labstack/echo/engine.Request.URL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。