- Building Microservices with Go
- Nic Jackson
- 282字
- 2021-07-15 17:28:03
TimeoutHandler
The TimeoutHandler function returns a Handler interface that runs h with the given time limit. When we investigate common patterns in Chapter 6, Microservice Frameworks, we will see just how useful this can be for avoiding cascading failures in your service:
func TimeoutHandler(h Handler, dt time.Duration, msg string) Handler
The new handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with a 503 Service Unavailable response with the given message (msg) in its body.
The last two handlers are especially interesting as they are, in effect, chaining handlers. This is a technique that we will go into more in-depth in a later chapter as it allows you to both practice clean code and also allows you to keep your code DRY.
I may have lifted most of the descriptions for these handlers straight from the Go documentation and you probably have already read these because you have read the documentation right? With Go, the documentation is excellent and writing documentation for your own packages is heavily encouraged, even enforced, if you use the golint command that comes with the standard package then this will report areas of your code which do not conform to the standards. I really recommend spending a little time browsing the standard docs when you are using one of the packages, not only will you learn the correct usage, you may learn that there is a better approach. You will certainly be exposed to good practice and style and you may even be able to keep working on the sad day that Stack Overflow stops working and the entire industry grinds to a halt.
- Go Web編程
- TensorFlow Lite移動端深度學習
- 編程卓越之道(卷3):軟件工程化
- Mastering JavaScript High Performance
- 軟件品質(zhì)之完美管理:實戰(zhàn)經(jīng)典
- OpenCV 4計算機視覺項目實戰(zhàn)(原書第2版)
- C++20高級編程
- 細說Python編程:從入門到科學計算
- PHP 7從零基礎到項目實戰(zhàn)
- SQL Server 2016 從入門到實戰(zhàn)(視頻教學版)
- 區(qū)塊鏈國產(chǎn)化實踐指南:基于Fabric 2.0
- 創(chuàng)意UI Photoshop玩轉(zhuǎn)移動UI設計
- HTML5移動Web開發(fā)
- Selenium WebDriver Practical Guide
- 網(wǎng)絡綜合布線與組網(wǎng)實戰(zhàn)指南