title: Golang. What to use? http.ServeFile(..) or http.FileServer(..)?
body: <p>I'm a little bit confused. Much of examples shows usage of both: <code>http.ServeFile(..)</code> and <code>http.FileServer(..)</code>, but seems they have very close functionality. Also I have found no information about how to set custom NotFound handler. </p>
  
  <pre><code>// This works and strip "/static/" fragment from path
  fs := http.FileServer(http.Dir("static"))
  http.Handle("/static/", http.StripPrefix("/static/", fs))
  
  // This works too, but "/static2/" fragment remains and need to be striped manually
  http.HandleFunc("/static2/", func(w http.ResponseWriter, r *http.Request) {
      http.ServeFile(w, r, r.URL.Path[1:])
  })
  
  http.ListenAndServe(":8080", nil)
  </code></pre>
  
  <p>I've tried to read source code and both of them use <code>serveFile(ResponseWriter, *Request, FileSystem, string, bool)</code> underlying function. However <code>http.FileServer</code> return <code>fileHandler</code> with its own <code>ServeHTTP()</code> method and make some preparation work before serving file (eg path.Clean()).</p>
  
  <p>So why need this separation? Which method better to use? And how can I set custom NotFound handler, for example when requested file not found?</p>