title: How to write a simple custom HTTP server in Go?
body: <p>I am new to Go and trying to write a custom HTTP server.  I'm getting a compilation error. How can I implement the <code>ServeHTTP</code> method in my code?</p>
  
  <p>My Code:</p>
  
  <pre><code>package main
  
  import (
      "net/http"
      "fmt"
      "io"
      "time"
  )
  
  
  func myHandler(w http.ResponseWriter, req *http.Request) {
      io.WriteString(w, "hello, world!\n")
  }
  
  
  func main() {
      // Custom http server
      s := &amp;http.Server{
          Addr:           ":8080",
          Handler:        myHandler,
          ReadTimeout:    10 * time.Second,
          WriteTimeout:   10 * time.Second,
          MaxHeaderBytes: 1 &lt;&lt; 20,
      }
  
      err := s.ListenAndServe()
      if err != nil {
          fmt.Printf("Server failed: ", err.Error())
      }
  }
  </code></pre>
  
  <p>Error while compiling:</p>
  
  <pre class="lang-none prettyprint-override"><code>.\hello.go:21: cannot use myHandler (type func(http.ResponseWriter, *http.Request)) as type http.Handler in field value:
      func(http.ResponseWriter, *http.Request) does not implement http.Handler (missing ServeHTTP method)
  </code></pre>