-
Notifications
You must be signed in to change notification settings - Fork 96
/
doc_test.go
80 lines (65 loc) · 1.42 KB
/
doc_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cas
import (
"fmt"
"log"
"net/http"
"net/url"
)
func ExampleRedirectToLogin() {
u, _ := url.Parse("https://cas.example.com")
c := NewClient(&Options{
URL: u,
})
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
RedirectToLogin(w, r)
})
err := http.ListenAndServe(":8080", h)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func ExampleRedirectToLogout() {
u, _ := url.Parse("https://cas.example.com")
c := NewClient(&Options{
URL: u,
})
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
RedirectToLogout(w, r)
})
err := http.ListenAndServe(":8080", h)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func ExampleIsAuthenticated() {
u, _ := url.Parse("https://cas.example.com")
c := NewClient(&Options{
URL: u,
})
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
if !IsAuthenticated(r) {
RedirectToLogout(w, r)
}
fmt.Fprintf(w, "Hello World\n")
})
err := http.ListenAndServe(":8080", h)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
func ExampleUsername() {
u, _ := url.Parse("https://cas.example.com")
c := NewClient(&Options{
URL: u,
})
h := c.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
if !IsAuthenticated(r) {
RedirectToLogout(w, r)
}
fmt.Fprintf(w, "Hello %s\n", Username(r))
})
err := http.ListenAndServe(":8080", h)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}