func main()

in apps/simple-frontend/main.go [24:63]


func main() {

	tr := &http.Transport{
		MaxIdleConns:    10,
		IdleConnTimeout: 30 * time.Second,
	}

	http.Handle("/api", xray.Handler(xray.NewFixedSegmentNamer("simple-frontend"), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

		backendEndpoint := os.Getenv("BACKEND_ENDPOINT")
		resp, err := ctxhttp.Get(r.Context(), xray.Client(&http.Client{Transport: tr}), backendEndpoint)

		if err != nil {
			fmt.Println(err)
			io.WriteString(w, "Unable to make request to: "+backendEndpoint)
			return
		}

		defer resp.Body.Close()

		if resp.StatusCode == http.StatusOK {
			body, err := ioutil.ReadAll(resp.Body)
			if err != nil {
				fmt.Println(err)
				return
			}
			w.Header().Set("Content-Type", "application/json")
			io.WriteString(w, string(body))
		}

	})))

	// 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)
}