本文整理匯總了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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}