Register registers shop routes on the given mux. These are PUBLIC endpoints (no auth required). shop/* 使用生产密钥(真实扣款),/shop-test/* 使用沙盒密钥。
(mux *http.ServeMux)
| 99 | // These are PUBLIC endpoints (no auth required). |
| 100 | // /shop/* 使用生产密钥(真实扣款),/shop-test/* 使用沙盒密钥。 |
| 101 | func (s *ShopAPI) Register(mux *http.ServeMux) { |
| 102 | s.checkoutLimiter = newCheckoutRateLimiter() |
| 103 | mux.HandleFunc("GET /shop/plans", s.listPlansHandler("live")) |
| 104 | mux.HandleFunc("POST /shop/checkout", s.createCheckoutHandler("live", "/shop")) |
| 105 | mux.HandleFunc("GET /shop-test/plans", s.requireAdmin(s.listPlansHandler("test"))) |
| 106 | mux.HandleFunc("POST /shop-test/checkout", s.requireAdmin(s.createCheckoutHandler("test", "/shop-test"))) |
| 107 | } |
| 108 | |
| 109 | // requireAdmin 要求请求携带有效的管理员 Bearer token。 |
| 110 | func (s *ShopAPI) requireAdmin(next http.HandlerFunc) http.HandlerFunc { |
no test coverage detected