本文整理汇总了Golang中github.com/ursiform/forest.App.ServeHTTP方法的典型用法代码示例。如果您正苦于以下问题:Golang App.ServeHTTP方法的具体用法?Golang App.ServeHTTP怎么用?Golang App.ServeHTTP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ursiform/forest.App
的用法示例。
在下文中一共展示了App.ServeHTTP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeRequest
func makeRequest(t *testing.T, app *forest.App,
params *requested, want *wanted) (*http.Response, *forest.Response) {
var request *http.Request
method := params.method
auth := params.auth
path := params.path
body := params.body
if body != nil {
request, _ = http.NewRequest(method, path, bytes.NewBuffer(body))
} else {
request, _ = http.NewRequest(method, path, nil)
}
if len(auth) > 0 {
request.AddCookie(&http.Cookie{Name: forest.SessionID, Value: auth})
}
response := httptest.NewRecorder()
app.ServeHTTP(response, request)
responseData := new(forest.Response)
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
t.Error(err)
return nil, responseData
}
if err := json.Unmarshal(responseBody, responseData); err != nil {
t.Errorf("unmarshal error: %v when attempting to read: %s",
err, string(responseBody))
return nil, responseData
}
if response.Code != want.code {
t.Errorf("%s %s want: %d (%s) got: %d %s, body: %s", method, path,
want.code, http.StatusText(want.code), response.Code,
http.StatusText(response.Code), string(responseBody))
return nil, responseData
}
if responseData.Success != want.success {
t.Errorf("%s %s should return success: %t", method, path, want.success)
return nil, responseData
}
return &http.Response{Header: response.Header()}, responseData
}