-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
50 lines (39 loc) · 1.17 KB
/
example_test.go
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
package cors_test
import (
"net/http"
"github.com/go-http-utils/cors"
)
func Example() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Hello World"))
})
http.ListenAndServe(":8080", cors.Handler(mux))
}
func ExampleOption_SetExposeHeaders() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Hello World"))
})
http.ListenAndServe(":8080", cors.Handler(mux,
cors.SetExposeHeaders([]string{"ETag"})))
}
func ExampleOption_SetCredentials() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Hello World"))
})
http.ListenAndServe(":8080", cors.Handler(mux,
cors.SetExposeHeaders([]string{"ETag"}), cors.SetCredentials(true)))
}
func ExampleOption_SetAllowOriginValidator() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte("Hello World"))
})
validator := func(_ *http.Request) string {
return "*"
}
http.ListenAndServe(":8080", cors.Handler(mux,
cors.SetAllowOriginValidator(validator)))
}