- Hands-On RESTful Web Services with Go
- Naren Yellavula
- 126字
- 2021-06-24 17:04:25
ServeMux – a basic router in Go
ServeMux is an HTTP request multiplexer. The HandleFunc we used in the preceding section is actually a method of ServeMux. By using ServeMux, we can handle multiple routes. We can also create our own multiplexer. A multiplexer handles the logic of separating routes with a function called ServeHTTP. So, if we create a Go struct with the ServeHTTP method, it can do the job as the in-built multiplexer.
Consider a route as a key in a Go dictionary (map) and a multiplexer as its value. Go finds the multiplexer from the route and tries to execute the ServeHTTP function. In the following section, we will see the usage of ServeMux by creating an API that generates UUID strings.
推薦閱讀
- Getting Started with ResearchKit
- 網絡爬蟲原理與實踐:基于C#語言
- Hands-On Microservices with Kotlin
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- Windows Phone 8 Game Development
- Penetration Testing with the Bash shell
- jQuery從入門到精通(微課精編版)
- PHP動態網站開發實踐教程
- Apache Solr for Indexing Data
- HTML5程序設計基礎教程
- 軟技能2:軟件開發者職業生涯指南
- WCF編程(第2版)
- Android開發權威指南(第二版)
- The Python Apprentice
- Flutter for Beginners