Can someone explain this function signature? I can't grep it.
func (h bytesHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (h bytesHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type bytesHandler []byte
The code func (h bytesHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.Write(h)
}
is a method declaration for the type bytesHandler. The (h bytesHandler) specifies id and type of the method receiver.This is from the http.Handler interface, so defining this method causes byteHandler to conform to the http.Handler interface.
There is no struct involved here and there doesn't need to be which is nice.