Golang http serve and help please

package main

import (“fmt”
type MyHandler struct{}
func (h *MyHandler) ServeHTTP (w http.ResponseWriter, r *http.Request){
fmt.Fprintf(w, “Hello Internet,Goodbye Local”)
func main() {
handler :=MyHandler{}
server :=http.Server{
Addr: “”,
Handler: &handler,

I don’t understand for what have I written func(h *MyHandler…) if I even don’t call it in main func.How does this snippet impact to realize code.How does this method is called if I don’t do this in func main and for what I declare empty struct?
Thank you!

It’s part of the contract, http.Server will call it

1 Like