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