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


Golang Context.Request方法代碼示例

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


在下文中一共展示了Context.Request方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Test_ParseAppendSeriesListRequest_OK

func Test_ParseAppendSeriesListRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"SeriesID": 2
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	s, err := ParseAppendSeriesListRequest(&ginCtx)
	if err != nil {
		t.Fatal(err)
	}

	expect := SeriesListRequestData{
		SeriesID: 2,
	}

	if expect.SeriesID != s.SeriesID {
		m := fmt.Sprintf("Expect %v was %v", expect, s)
		t.Fatal(m)
	}

}
開發者ID:tochti,項目名稱:sj,代碼行數:32,代碼來源:utils_test.go

示例2: Test_ParseUserRequest_OK

func Test_ParseUserRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"Name": "name",
			"Password": "password"
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	u, err := ParseNewUserRequest(&ginCtx)

	expect := User{
		Name:     "name",
		Password: "password",
	}

	if err := EqualUser(expect, u); err != nil {
		t.Fatal(err)
	}

}
開發者ID:tochti,項目名稱:sj,代碼行數:30,代碼來源:utils_test.go

示例3: Test_ParseSeriesRequest_OK

func Test_ParseSeriesRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"Title": "Title",
			"Image": "Image"
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	s, err := ParseNewSeriesRequest(&ginCtx)

	expect := Series{
		Title: "Title",
		Image: "Image",
	}

	if err := EqualSeries(expect, s); err != nil {
		t.Fatal(err)
	}

}
開發者ID:tochti,項目名稱:sj,代碼行數:30,代碼來源:utils_test.go

示例4: Test_ParseUpdateLastWatchedRequest_OK

func Test_ParseUpdateLastWatchedRequest_OK(t *testing.T) {
	data := `
	{
		"Data": {
			"UserID": 1,
			"SeriesID": 2,
			"Session": 3,
			"Episode": 4
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	s, err := ParseUpdateLastWatchedRequest(&ginCtx)
	if err != nil {
		t.Fatal(err)
	}

	expect := LastWatched{
		SeriesID: 2,
		Session:  3,
		Episode:  4,
	}

	if expect.SeriesID != s.SeriesID ||
		expect.Session != s.Session ||
		expect.Episode != s.Episode {
		m := fmt.Sprintf("Expect %v was %v", expect, s)
		t.Fatal(m)
	}

}
開發者ID:tochti,項目名稱:sj,代碼行數:39,代碼來源:utils_test.go

示例5: Test_ParseNewSeriesRequest_FailMissingFields

func Test_ParseNewSeriesRequest_FailMissingFields(t *testing.T) {
	data := `
	{
		"Data": {
			"Title": "Title"
		}
	}`

	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "/", body)
	if err != nil {
		t.Fatal(err)
	}

	ginCtx := gin.Context{}
	ginCtx.Request = req

	_, err = ParseNewSeriesRequest(&ginCtx)
	expect := NewMissingFieldError("Image")
	if err.Error() != expect.Error() {
		t.Fatal("Expect", expect, "was", err)
	}
}
開發者ID:rrawrriw,項目名稱:sj-handler,代碼行數:23,代碼來源:handler_test.go


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