-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcachecontrol_example_test.go
More file actions
53 lines (43 loc) · 1.34 KB
/
Copy pathcachecontrol_example_test.go
File metadata and controls
53 lines (43 loc) · 1.34 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
45
46
47
48
49
50
51
52
53
package cachecontrol_test
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
cachecontrol "go.eigsys.de/gin-cachecontrol/v2"
)
func ExampleNew() {
router := gin.Default()
router.Use(cachecontrol.New(cachecontrol.Config{
MustRevalidate: true,
NoCache: false,
NoStore: false,
NoTransform: false,
Public: true,
Private: false,
ProxyRevalidate: true,
MaxAge: cachecontrol.Duration(30 * time.Minute),
SMaxAge: nil,
Immutable: false,
StaleWhileRevalidate: cachecontrol.Duration(2 * time.Hour),
StaleIfError: cachecontrol.Duration(2 * time.Hour),
}))
router.GET("/", func(ginCtx *gin.Context) {
ginCtx.String(http.StatusOK, "Hello, Gopher!")
})
_ = router.Run()
}
func ExampleNewWithOptions() {
router := gin.Default()
router.Use(cachecontrol.NewWithOptions(
cachecontrol.WithMustRevalidate(true),
cachecontrol.WithPublic(true),
cachecontrol.WithProxyRevalidate(true),
cachecontrol.WithMaxAge(cachecontrol.Duration(30*time.Minute)),
cachecontrol.WithStaleWhileRevalidate(cachecontrol.Duration(2*time.Hour)),
cachecontrol.WithStaleIfError(cachecontrol.Duration(2*time.Hour)),
))
router.GET("/", func(ginCtx *gin.Context) {
ginCtx.String(http.StatusOK, "Hello, Gopher!")
})
_ = router.Run()
}