github.com/epsagon/epsagon-go@v1.39.0/example/http_mux/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io" 6 "io/ioutil" 7 "net/http" 8 9 "github.com/epsagon/epsagon-go/epsagon" 10 epsagonhttp "github.com/epsagon/epsagon-go/wrappers/net/http" 11 ) 12 13 func main() { 14 mux := http.NewServeMux() 15 mux.HandleFunc("/ping", epsagonhttp.WrapHandleFunc( 16 epsagon.NewTracerConfig("test-http-mux", ""), 17 func(w http.ResponseWriter, req *http.Request) { 18 19 client := http.Client{ 20 Transport: epsagonhttp.NewTracingTransport(req.Context())} 21 resp, err := client.Get("http://example.com") 22 23 if err == nil { 24 respBody, err := ioutil.ReadAll(resp.Body) 25 if err == nil { 26 fmt.Println("First 1000 bytes recieved: ", string(respBody[:1000])) 27 } 28 } 29 io.WriteString(w, "pong\n") 30 }, 31 "my-test-function", 32 "test.hostname.com", 33 )) 34 35 http.ListenAndServe(":8080", mux) 36 }