1
0

main.go 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. paths := pathway.New()
  23. http.HandleFunc("/health", okHandler)
  24. http.HandleFunc("/favicon.ico", emptyHandler)
  25. http.HandleFunc("/robots.txt", emptyHandler)
  26. http.HandleFunc("/", paths.ServeHTTP)
  27. err := http.ListenAndServe(":8080", nil)
  28. if err != nil {
  29. info("%s", err.Error())
  30. }
  31. }
  32. func info(msg string, args ...interface{}) {
  33. log.Printf("INFO | "+msg, args...)
  34. }
  35. func debug(msg string, args ...interface{}) {
  36. if len(debugging) > 0 {
  37. log.Printf("DEBUG | "+msg, args...)
  38. }
  39. }