Skip to content

Commit

Permalink
Fix test and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robskillington committed Nov 20, 2020
1 parent 61d7259 commit b89b509
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/query/api/v1/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (h *Handler) RegisterRoutes() error {
if err := h.registry.Register(queryhttp.RegisterOptions{
Path: custom.Route(),
Handler: handler,
Methods: custom.Methods(),
Methods: methods(method),
}); err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions src/query/util/queryhttp/queryhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
})
)

// NewEndpointRegistry returns a new endpoint registry.
func NewEndpointRegistry(
router *mux.Router,
instrumentOpts instrument.Options,
Expand All @@ -52,6 +53,8 @@ func NewEndpointRegistry(
}
}

// EndpointRegistry is an endpoint registry that can register routes
// and instrument them.
type EndpointRegistry struct {
router *mux.Router
instrumentOpts instrument.Options
Expand All @@ -64,13 +67,15 @@ type routeKey struct {
method string
}

// RegisterOptions are options for registering a handler.
type RegisterOptions struct {
Path string
PathPrefix string
Handler http.Handler
Methods []string
}

// Register registers an endpoint.
func (r *EndpointRegistry) Register(
opts RegisterOptions,
middlewareOpts ...logging.MiddlewareOption,
Expand Down Expand Up @@ -140,11 +145,14 @@ func (r *EndpointRegistry) Register(
return nil
}

// RegisterPathsOptions is options for registering multiple paths
// with the same handler.
type RegisterPathsOptions struct {
Handler http.Handler
Methods []string
}

// RegisterPaths registers multiple paths for the same handler.
func (r *EndpointRegistry) RegisterPaths(
paths []string,
opts RegisterPathsOptions,
Expand All @@ -162,6 +170,8 @@ func (r *EndpointRegistry) RegisterPaths(
return nil
}

// PathRoute resolves a registered route that was registered by path and method,
// not by path prefix.
func (r *EndpointRegistry) PathRoute(path, method string) (*mux.Route, bool) {
key := routeKey{
path: path,
Expand All @@ -171,6 +181,16 @@ func (r *EndpointRegistry) PathRoute(path, method string) (*mux.Route, bool) {
return h, ok
}

// PathPrefixRoute resolves a registered route that was registered by path
// prefix, not by path and method.
func (r *EndpointRegistry) PathPrefixRoute(pathPrefix string) (*mux.Route, bool) {
key := routeKey{
pathPrefix: pathPrefix,
}
h, ok := r.registered[key]
return h, ok
}

// Walk walks the router and all its sub-routers, calling walkFn for each route
// in the tree. The routes are walked in the order they were added. Sub-routers
// are explored depth-first.
Expand Down

0 comments on commit b89b509

Please sign in to comment.