func main()

in content/intermediate/245_x-ray/sample-front.files/main.go [30:58]


func main() {

	http.Handle("/api", xray.Handler(xray.NewFixedSegmentNamer("x-ray-sample-front-k8s"), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

		slow := param(r, "slow", "false")
		repeat := param(r, "repeat", "false")

		count := 1
		if repeat == "true" {
			count = 20
		}

		for idx := 0; idx < count; idx++ {
			if resp, err := backend(r, slow); err == nil {
				io.WriteString(w, fmt.Sprintf("%s<br>", resp))
			} else {
				io.WriteString(w, fmt.Sprintf("Unable to make request to: http://x-ray-sample-back-k8s.default.svc.cluster.local: %v<br>", err))
			}
		}
	})))

	// Write the landing page
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("Content-Type", "text/html")
			io.WriteString(w, html)
	})

	http.ListenAndServe(":8080", nil)
}