reference query parameters in config.Service

This commit is contained in:
Adrien Marquès 2020-03-16 11:32:37 +01:00
parent e7f10723a6
commit 12417f7f1c
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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)