What is s *server doing here? What it means?

type server struct{}

func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")
    w.Write([]byte(`{"message": "hello world"}`))

It’s the receiver for the function. Which is the struct above.
Kinda like a method in a class.

So objects of type server will have a ServeHTTP method callable with dot notation.

1 Like