forked from akrylysov/algnhsa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
34 lines (28 loc) · 772 Bytes
/
example_test.go
File metadata and controls
34 lines (28 loc) · 772 Bytes
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
package algnhsa_test
import (
"fmt"
"net/http"
"strconv"
"github.com/akrylysov/algnhsa"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("index"))
}
func addHandler(w http.ResponseWriter, r *http.Request) {
f, _ := strconv.Atoi(r.FormValue("first"))
s, _ := strconv.Atoi(r.FormValue("second"))
w.Header().Set("X-Hi", "foo")
fmt.Fprintf(w, "%d", f+s)
}
func contextHandler(w http.ResponseWriter, r *http.Request) {
proxyReq, ok := algnhsa.ProxyRequestFromContext(r.Context())
if ok {
fmt.Fprint(w, proxyReq.RequestContext.AccountID)
}
}
func Example() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/add", addHandler)
http.HandleFunc("/context", contextHandler)
algnhsa.ListenAndServe(http.DefaultServeMux, nil)
}