July 2017
Beginner to intermediate
358 pages
10h 54m
English
A FileServer function returns a handler that serves HTTP requests with the contents of the filesystem. This can be used to serve static files such as images or other content that is stored on the file system:
func FileServer(root FileSystem) Handler
Take a look at the following code:
http.Handle("/images", http.FileServer(http.Dir("./images")))
This allows us to map the contents of the file system path ./images to the server route /images, Dir implements a file system which is restricted to a specific directory tree, the FileServer method uses this to be able to serve the assets.
Read now
Unlock full access