app.go 591 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "errors"
  4. "log"
  5. "net/http"
  6. )
  7. const (
  8. addr = ":8080"
  9. )
  10. /*
  11. @app.route("/")
  12. def index():
  13. */
  14. func RouteIndex(w http.ResponseWriter, r *http.Request) {
  15. w.Write([]byte("Hello World!"))
  16. }
  17. func setupRoutes(mux *http.ServeMux) {
  18. mux.HandleFunc("/", RouteIndex)
  19. }
  20. func main() {
  21. mux := http.NewServeMux()
  22. setupRoutes(mux)
  23. log.Printf("Listening on http://localhost%s", addr)
  24. if err := http.ListenAndServe(addr, mux); err != nil {
  25. if !errors.Is(err, http.ErrServerClosed) {
  26. log.Printf("Server error: %v\n", err)
  27. return
  28. }
  29. }
  30. log.Println("Server shutdown")
  31. }