Hacker News new | ask | show | jobs
by zek 4504 days ago
you have to get used to get go's backwards type declaration. This is defining a method on h which is a byteHandler struct called serve which takes a http.ResponseWriter and Request and returns nothing.

This is from the http.Handler interface, so defining this method causes byteHandler to conform to the http.Handler interface.

1 comments

byteHandler is not a struct it's a byte slice. This is actually somewhat important since it highlights a nice feature of go where you can declare methods on any baseType by aliasing them to your own type.

There is no struct involved here and there doesn't need to be which is nice.

I've found that when discussing Go, the terms `struct` and `type` are usually used interchangeably. Yes it's factually incorrect, but the message is at least intelligible.