main.go 778 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "os"
  8. )
  9. func main() {
  10. port := os.Getenv("PORT")
  11. if port == "" {
  12. port = "80"
  13. }
  14. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  15. w.WriteHeader(http.StatusOK)
  16. w.Header().Set("Content-Type", "text/html; charset=utf-8")
  17. file, err := ioutil.ReadFile("./assets/init.html")
  18. if err != nil {
  19. http.Error(w, err.Error(), http.StatusInternalServerError)
  20. log.Fatal("Can't find error html page")
  21. }
  22. w.Write(file)
  23. })
  24. // return 200 on healthz path
  25. http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
  26. w.WriteHeader(http.StatusOK)
  27. w.Write([]byte("healthy!"))
  28. })
  29. if err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil); err != nil {
  30. panic(err)
  31. }
  32. }