mux.go 434 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. )
  7. func handler(w http.ResponseWriter, r *http.Request) {
  8. fmt.Fprintln(w, "URL:", r.URL.String())
  9. }
  10. func main() {
  11. mux := http.NewServeMux()
  12. mux.HandleFunc("/", handler)
  13. server := http.Server{
  14. Addr: ":8080",
  15. Handler: mux,
  16. ReadTimeout: 10 * time.Second,
  17. WriteTimeout: 10 * time.Second,
  18. }
  19. fmt.Println("starting server at :8080")
  20. server.ListenAndServe()
  21. }