- Building Microservices with Go
- Nic Jackson
- 94字
- 2021-07-15 17:28:03
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.
推薦閱讀
- Java應用與實戰
- CMDB分步構建指南
- TensorFlow Lite移動端深度學習
- 無代碼編程:用云表搭建企業數字化管理平臺
- Developing Middleware in Java EE 8
- 趣學Python算法100例
- Git高手之路
- aelf區塊鏈應用架構指南
- Cassandra Data Modeling and Analysis
- MATLAB定量決策五大類問題
- INSTANT Mercurial SCM Essentials How-to
- Learning Data Mining with R
- Java編程的邏輯
- Multithreading in C# 5.0 Cookbook
- 從Excel到Python數據分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應用