-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
44 lines (37 loc) · 1.36 KB
/
Copy pathconfig.go
File metadata and controls
44 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package httpcache
import (
"net/http"
"time"
)
var (
defaultAllowedStatusCodes = []int{http.StatusOK}
defaultAllowedMethods = []string{http.MethodGet}
defaultExpiryTime = time.Duration(60*24*7) * time.Minute
)
// DefaultConfig creates a [Config] with default values, namely:
// - AllowedStatusCodes: [http.StatusOK]
// - AllowedMethods: [http.MethodGet]
// - ExpiryTime: 7 days.
var DefaultConfig = NewConfigBuilder().
WithAllowedStatusCodes(defaultAllowedStatusCodes).
WithAllowedMethods(defaultAllowedMethods).
WithExpiryTime(defaultExpiryTime).
Build()
// Config describes the configuration to use when saving and reading responses
// from [Cache] using the [Transport].
type Config struct {
// AllowedStatusCodes describes if a HTTP response should be saved by
// checking that it's status code is accepted by [Cache]. If the HTTP
// response's status code is not in AllowedStatusCodes, then do not persist.
//
// This is a required field.
AllowedStatusCodes []int
// AllowedMethods describes if a HTTP response should be saved by checking
// if the HTTP request's method is accepted by the [Cache]. If the HTTP
// request's method is not in AllowedMethods, then do not persist.
//
// This is a required field.
AllowedMethods []string
// ExpiryTime describes when a HTTP response should be considered invalid.
ExpiryTime *time.Duration
}