Documentation
¶
Overview ¶
Make HTTP requests.
Index ¶
Constants ¶
const ( DebugKeepIgnore = iota DebugKeepIndex DebugKeepData )
Variables ¶
This section is empty.
Functions ¶
func ClearCache ¶
Clear cache.
Each filter return a duration to keep the request. If meta.Time < now+maxAge => remove it. The filter should not the edit meta.
func Debug ¶
func Debug(fsys writefs.CompleteFS, keeper func(m *Meta) int) error
Debug create cacheRoot/index.html with a index of all cache request. The keeper return a const like DebugKeepIgnore.
Types ¶
type Fetcher ¶
type Fetcher interface {
// Make a HTTP GET request and return response.
// If response code is out of [200,299] return an error.
// Return fs.ErrNotExist if the fetcher is a cache, and not found the response.
Fetch(*Request) (*Response, error)
// Static name of the fetcher: net, cache...
// Use this for the log
Name() string
}
func Net ¶
func Net(roundTripper http.RoundTripper, cache writefs.CreateOpener, delay map[string]time.Duration) Fetcher
type Meta ¶
type Meta struct {
Time time.Time `json:"time"`
Method string `json:"requestMethod"`
RawURL string `json:"requestURL"`
URL *url.URL `json:"-"`
RequestHeader http.Header `json:"requestHeader"`
RequestBody []byte `json:"requestBody"`
Status int `json:"status"`
ResponseHeader http.Header `json:"responseHeader"`
// Response body used only for test
ResponseBody []byte `json:"-"`
// contains filtered or unexported fields
}
Information about a request and response, saved in cache file or used for the test.
func ReadOnlyMeta ¶
Read only header of the file, then you can read the body.
func (*Meta) ID ¶
Calculate the ID with Request.ID. Cache the id, so you must not edit m after this method call.
type Request ¶
type Request struct {
Method string
URL *url.URL
Header http.Header
Body []byte
// contains filtered or unexported fields
}
func Fmt ¶
Like URL but call fmt.Sprintf to create the url.
func R ¶
Easy way to create a request. If error, create a request with url: scheme=err, path=rawURL.
Headers is key1, value1, key2, value2 ... If headers length is odd, the last element is ignored.
func URL ¶
Create a GET *Request from a URL. If error, create a request with url: scheme=err, path=rawURL.
func (*Request) ID ¶
Cononize the request and return the identifier. The ID is a hash of all fields encoded in hexadecimal.
The ID is saved in the request, so after call to this method, you must not edit the request.
type Response ¶
type Response struct {
Status int // e.g. 200
Header http.Header
Body io.ReadCloser
}
func ReadResponse ¶
func ReadResponse(r io.ReadCloser) (*Response, error)