From 12417f7f1cd2dcdaf990ff16fa0b37991fd35af9 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 16 Mar 2020 11:32:37 +0100 Subject: [PATCH] reference query parameters in config.Service --- internal/config/service.go | 12 ++++++++++++ internal/config/types.go | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/internal/config/service.go b/internal/config/service.go index abe5e06..18d9b62 100644 --- a/internal/config/service.go +++ b/internal/config/service.go @@ -10,6 +10,7 @@ import ( ) var braceRegex = regexp.MustCompile(`^{([a-z_-]+)}$`) +var queryRegex = regexp.MustCompile(`^GET@([a-z_-]+)$`) // Match returns if this service would handle this HTTP request func (svc *Service) Match(req *http.Request) bool { @@ -117,6 +118,17 @@ func (svc *Service) checkAndFormatInput(types []datatype.T) error { return fmt.Errorf("%s: %w", paramName, ErrUnspecifiedBraceCapture) } iscapture = true + + } else if matches := queryRegex.FindAllStringSubmatch(paramName, -1); len(matches) > 0 && len(matches[0]) > 1 { + + queryName := matches[0][1] + + // init map + if svc.Query == nil { + svc.Query = make(map[string]*Parameter) + } + svc.Query[queryName] = param + } // use param name if no rename diff --git a/internal/config/types.go b/internal/config/types.go index c76e36a..7ce33c1 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -24,7 +24,13 @@ type Service struct { // Download *bool `json:"download"` // Output map[string]*Parameter `json:"out"` + // references to url parameters + // format: '/uri/{param}' Captures []*BraceCapture + + // references to Query parameters + // format: 'GET@paranName' + Query map[string]*Parameter } // Parameter represents a parameter definition (from api.json)