func main()

in blogs/eks-bulkhead-pattern-circuit-breaker/price-app/main.go [26:67]


func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = defaultPort
	}
	log.Printf("PORT is: %v", port)

	databaseDelay, err := time.ParseDuration(os.Getenv("DATABASE_DELAY"))
	if err != nil {
		databaseDelay, err = time.ParseDuration(defaultDatabaseDelay)
	}
	log.Printf("DATABASE_DELAY is: %s", databaseDelay)

	// GET  /health
	r := mux.NewRouter()
	r.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {}).Methods("GET")

	// POST /price
	r.HandleFunc("/price", func(w http.ResponseWriter, r *http.Request) {
		log.Printf("%s %s", r.Method, r.RequestURI)
		time.Sleep(databaseDelay)

		fmt.Fprintf(w, "%s", "{ \"status\": \"created\" }")
	}).Methods("POST")

	// GET /price/$id
	r.HandleFunc("/price/{id}", func(w http.ResponseWriter, r *http.Request) {
		log.Printf("%s %s", r.Method, r.RequestURI)

		fmt.Fprintf(w, "%s", "{ \"value\": \"23.10\" }")
	}).Methods("GET")

	h2s := &http2.Server{}
	h1s := &http.Server{
		Addr:         "0.0.0.0:" + port,
		Handler:      h2c.NewHandler(r, h2s),
		ReadTimeout:  60 * time.Second,
		WriteTimeout: 60 * time.Second,
	}

	log.Fatal(h1s.ListenAndServe())
}