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

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.

主站蜘蛛池模板: 吉木萨尔县| 治多县| 仙居县| 西平县| 临江市| 正定县| 平昌县| 福鼎市| 彩票| 九龙城区| 周口市| 九龙城区| 南乐县| 鹿泉市| 五大连池市| 三都| 漠河县| 开远市| 塔城市| 庄浪县| 曲阳县| 平舆县| 浠水县| 榕江县| 镇沅| 民乐县| 台东市| 吉林省| 霍山县| 宣城市| 绥中县| 烟台市| 万安县| 昌邑市| 甘肃省| 张北县| 留坝县| 广丰县| 肃宁县| 绿春县| 宁城县|