12345678910111213141516171819202122232425262728293031323334353637 |
- package main
- import (
- "errors"
- "log"
- "net/http"
- )
- const (
- addr = ":8080"
- )
- /*
- @app.route("/")
- def index():
- */
- func RouteIndex(w http.ResponseWriter, r *http.Request) {
- http.Redirect(w, r, "/contacts", http.StatusSeeOther)
- }
- func setupRoutes(mux *http.ServeMux) {
- mux.HandleFunc("/", RouteIndex)
- mux.Handle("/contacts", http.NotFoundHandler())
- }
- func main() {
- mux := http.NewServeMux()
- setupRoutes(mux)
- log.Printf("Listening on http://localhost%s", addr)
- if err := http.ListenAndServe(addr, mux); err != nil {
- if !errors.Is(err, http.ErrServerClosed) {
- log.Printf("Server error: %v\n", err)
- return
- }
- }
- log.Println("Server shutdown")
- }
|