-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwrapexamples_test.go
More file actions
46 lines (34 loc) · 902 Bytes
/
wrapexamples_test.go
File metadata and controls
46 lines (34 loc) · 902 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
35
36
37
38
39
40
41
42
43
44
45
46
package gaelog_test
import (
"fmt"
"log"
"net/http"
"os"
"github.com/mtraver/gaelog"
)
func ExampleWrapWithID() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
gaelog.Warningf(ctx, "Some important info right here, that's for sure")
fmt.Fprintf(w, "Hey")
})
http.Handle("/", gaelog.WrapWithID(handler, "my_log"))
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}
func ExampleWrap() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
gaelog.Warningf(ctx, "Some important info right here, that's for sure")
fmt.Fprintf(w, "Hey")
})
http.Handle("/", gaelog.Wrap(handler))
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}