0

Go-restful is a good and easy to use Go RESTful style framework, but here is something i am wondering about (this is just a piece of code):


func main() {
    service := new(restful.WebService)

    service.Route(
    service.GET("/{user-id}").To(FindUser).
    Returns(200, "hello", noMessageValue).
    Returns(500, "internal error", noMessageValue))
    restful.Add(service)
    http.ListenAndServe(":8080", nil)
} 

This code can work well. Notice the last line http.ListenAndServe(":8080", nil), it does not pass any handler to the ListenAndServe method (it passes a nil value instead), just the port string. Does anyone know how go-restful implements handler binding ?

Zoyd
  • 3,449
  • 1
  • 18
  • 27
fisafoer
  • 273
  • 1
  • 2
  • 6

1 Answers1

0

Passing nil as a handler is a common practice in Go. As the specs say,

Handler is typically nil, in which case the DefaultServeMux is used.

DefaultServeMux is just a convenience global variable in http. So, go-restful just uses it by default.

bereal
  • 32,519
  • 6
  • 58
  • 104