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

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.

主站蜘蛛池模板: 五常市| 青岛市| 苏尼特右旗| 黄平县| 偃师市| 平原县| 新沂市| 黄骅市| 禄丰县| 德庆县| 饶河县| 汉沽区| 疏附县| 大足县| 宜都市| 区。| 高密市| 周至县| 兴和县| 中牟县| 延安市| 三河市| 龙南县| 鄂州市| 三亚市| 灌南县| 共和县| 曲沃县| 孝义市| 旬阳县| 黄陵县| 射洪县| 南充市| 东莞市| 万安县| 威宁| 巴彦淖尔市| 萝北县| 香港| 丰镇市| 阿巴嘎旗|