February 2018
Intermediate to advanced
340 pages
9h 43m
English
The net/http package provides the functions ServeFile and FileServer, which are designed to serve the static files. The ServeFile function just consumes the ResponseWriter and Request with the given file path argument and writes the content of the file to the response.
The FileServer function creates the whole Handler which consumes the FileSystem argument. The preceding example uses the Dir type, which implements the FileSystem interface. The FileSystem interface requires implementing the Open method, which consumes string and returns the actual File for the given path.
Read now
Unlock full access