http server
Fill in the blanks in line A and B, to respond to any http requests on port 8000 with response "hello"
package main
import (
"fmt"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
___ //A
})
// B
}
Answer
package main
import (
"fmt"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello")
})
http.ListenAndServe(":8000", mux)
}