Golang ¿Qué usar? http.ServeFile (..) o http.FileServer (..)?

Estoy un poco confundido. Muchos de los ejemplos muestran el uso de ambos:http.ServeFile(..) yhttp.FileServer(..), pero parece que tienen una funcionalidad muy cercana. Tampoco he encontrado información sobre cómo configurar el controlador NotFound personalizado.

// 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)

He intentado leer el código fuente y ambos usanserveFile(ResponseWriter, *Request, FileSystem, string, bool) función subyacente sin embargohttp.FileServer regresofileHandler con su propioServeHTTP() método y hacer un trabajo de preparación antes de servir el archivo (por ejemplo, path.Clean ()).

Entonces, ¿por qué necesita esta separación? ¿Qué método es mejor usar? ¿Y cómo puedo configurar un controlador NotFound personalizado, por ejemplo, cuando no se encuentra el archivo solicitado?

Respuestas a la pregunta(2)

Su respuesta a la pregunta