- 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.
推薦閱讀
- HTML5+CSS3王者歸來
- jQuery Mobile Web Development Essentials(Third Edition)
- 大學(xué)計算機(jī)應(yīng)用基礎(chǔ)實踐教程
- C/C++算法從菜鳥到達(dá)人
- OpenNI Cookbook
- Internet of Things with the Arduino Yún
- Mastering macOS Programming
- Python機(jī)器學(xué)習(xí):手把手教你掌握150個精彩案例(微課視頻版)
- SQL Server 2016 從入門到實戰(zhàn)(視頻教學(xué)版)
- WCF技術(shù)剖析(卷1)
- Less Web Development Cookbook
- Java服務(wù)端研發(fā)知識圖譜
- Scala編程(第4版)
- ArcGIS Blueprints
- 大學(xué)計算機(jī)基礎(chǔ)