RegisterRoute registers a single route enforcing HTTP methods. A single route is expected to be specific about which HTTP methods are supported.
(path string, handler http.Handler, auth bool, method string, methods ...string)
| 188 | // RegisterRoute registers a single route enforcing HTTP methods. A single |
| 189 | // route is expected to be specific about which HTTP methods are supported. |
| 190 | func (a *API) RegisterRoute(path string, handler http.Handler, auth bool, method string, methods ...string) { |
| 191 | methods = append([]string{method}, methods...) |
| 192 | |
| 193 | level.Debug(a.logger).Log("msg", "api: registering route", "methods", strings.Join(methods, ","), "path", path, "auth", auth) |
| 194 | |
| 195 | if auth { |
| 196 | handler = a.AuthMiddleware.Wrap(handler) |
| 197 | } |
| 198 | |
| 199 | if a.cfg.ResponseCompression { |
| 200 | handler = gzhttp.GzipHandler(handler) |
| 201 | } |
| 202 | if a.HTTPHeaderMiddleware != nil { |
| 203 | handler = a.HTTPHeaderMiddleware.Wrap(handler) |
| 204 | } |
| 205 | |
| 206 | if len(methods) == 0 { |
| 207 | a.server.HTTP.Path(path).Handler(handler) |
| 208 | return |
| 209 | } |
| 210 | a.server.HTTP.Path(path).Methods(methods...).Handler(handler) |
| 211 | } |
| 212 | |
| 213 | func (a *API) RegisterRoutesWithPrefix(prefix string, handler http.Handler, auth bool, methods ...string) { |
| 214 | level.Debug(a.logger).Log("msg", "api: registering route", "methods", strings.Join(methods, ","), "prefix", prefix, "auth", auth) |