- 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.
推薦閱讀
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- C++程序設計(第3版)
- Python 深度學習
- 趣學Python算法100例
- Wireshark Network Security
- Visual Basic程序設計實踐教程
- Learning jQuery(Fourth Edition)
- Python Essentials
- 計算機應用基礎教程(Windows 7+Office 2010)
- Instant Debian:Build a Web Server
- Unity Character Animation with Mecanim
- C語言程序設計實訓教程與水平考試指導
- Python 3 Object:oriented Programming(Second Edition)
- Sails.js Essentials
- Ext JS 4 Plugin and Extension Development