官术网_书友最值得收藏!

FileServer

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.

主站蜘蛛池模板: 杨浦区| 兰考县| 望江县| 宣恩县| 宣城市| 满城县| 湟中县| 开平市| 卢氏县| 顺平县| 沙坪坝区| 上杭县| 海原县| 临西县| 定兴县| 额济纳旗| 和平县| 布尔津县| 新乡县| 台湾省| 城固县| 武夷山市| 城口县| 清原| 随州市| 佛山市| 阳新县| 罗平县| 盘山县| 太湖县| 临邑县| 恩平市| 海宁市| 宜兴市| 五原县| 呼和浩特市| 玉环县| 乌兰浩特市| 桂东县| 长宁区| 芮城县|