- 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.
推薦閱讀
- Mastering JavaScript Functional Programming
- Software Defined Networking with OpenFlow
- 自制編譯器
- C語言程序設計教程(第2版)
- 數據結構與算法JavaScript描述
- Java程序員面試算法寶典
- Linux環境編程:從應用到內核
- Web全棧工程師的自我修養
- Java軟件開發基礎
- Visual C++應用開發
- Building Minecraft Server Modifications
- GameMaker Essentials
- Python預測分析與機器學習
- Mastering Embedded Linux Programming
- Elasticsearch Blueprints