main.go 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "git.nxdomain.nl/mattijs/pathway"
  6. )
  7. var (
  8. // variables to set during build-time
  9. debugging = ""
  10. version = "0.0-undefined"
  11. buildtime = "0000-00-00T00:00:00+0000"
  12. )
  13. func okHandler(w http.ResponseWriter, r *http.Request) {
  14. w.WriteHeader(http.StatusOK)
  15. w.Write([]byte("ok"))
  16. }
  17. func emptyHandler(w http.ResponseWriter, r *http.Request) {
  18. w.WriteHeader(http.StatusOK)
  19. }
  20. func main() {
  21. info("pathway version:%s buildtime:%s", version, buildtime)
  22. http.HandleFunc("/health", okHandler)
  23. http.HandleFunc("/favicon.ico", emptyHandler)
  24. http.HandleFunc("/robots.txt", emptyHandler)
  25. http.HandleFunc("/", pathway.pathHandler)
  26. err := http.ListenAndServe(":8080", nil)
  27. if err != nil {
  28. info("%s", err.Error())
  29. }
  30. }
  31. func info(msg string, args ...interface{}) {
  32. log.Printf("INFO | "+msg, args...)
  33. }
  34. func debug(msg string, args ...interface{}) {
  35. if len(debugging) > 0 {
  36. log.Printf("DEBUG | "+msg, args...)
  37. }
  38. }