net/http Flashcards

1
Q

What function starts the default http server?

A
func ListenAndServer(addr string, handler Handler) error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a simple handler?

A
f := func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf("Hello, world!\n")
h := http.HandlerFunc(f)
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What settings help with a client that’s slow to send it request to the server?

A
http.Server {
    ReadTimeout time.Duration
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What would with a slow server handler?

A

Wrap it with the http.TimeoutHandler

http.TimeoutHandler(h http.Handler, dt time.Duration, msg string) http.Handler
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does net/http provide to deal with multiple handlers?

A

The HTTP request multiplexer http.ServeMux. The multiplexer is itself a http.Handler.

mux := http.NewServeMux()
mux.HandleFunc("/1", handleOne)
mux.HandleFunc("/2", handleTwo)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly