- 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.
推薦閱讀
- Apache Oozie Essentials
- Oracle 11g從入門到精通(第2版) (軟件開發視頻大講堂)
- Delphi程序設計基礎:教程、實驗、習題
- 構建移動網站與APP:HTML 5移動開發入門與實戰(跨平臺移動開發叢書)
- Android Application Development Cookbook(Second Edition)
- Mastering Ubuntu Server
- Mastering C# Concurrency
- Data Analysis with IBM SPSS Statistics
- Mastering JBoss Enterprise Application Platform 7
- 零基礎趣學C語言
- Clojure for Machine Learning
- JBoss:Developer's Guide
- JSP程序設計實例教程(第2版)
- Visual Basic程序設計實驗指導及考試指南
- R的極客理想:量化投資篇