http server

Fill in the blanks in line A and B, to respond to any http requests on port 8000 with response "hello"

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. func main() {
  7. mux := http.NewServeMux()
  8. mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
  9. ___ //A
  10. })
  11. // B
  12. }

Answer

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. func main() {
  7. mux := http.NewServeMux()
  8. mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
  9. fmt.Fprintf(w, "hello")
  10. })
  11. http.ListenAndServe(":8000", mux)
  12. }