providers: Add provider for URL functions

This commit is contained in:
2024-12-06 00:12:50 -05:00
parent 541f2f0620
commit c6b5fd7eeb
2 changed files with 32 additions and 0 deletions

30
providers/url/url.go Normal file
View File

@@ -0,0 +1,30 @@
package url
import "net/url"
import "html/template"
import "git.tebibyte.media/sashakoshka/step"
var _ step.FuncProvider = new(Provider)
// Provider provides URL functions.
type Provider struct {
}
// FuncMap fulfills the step.FuncProvider interface.
func (this *Provider) FuncMap () template.FuncMap {
return template.FuncMap {
"parseQuery": funcParseQuery,
}
}
func funcParseQuery (query string) url.Values {
// wrapped here because the query might contain all sorts of nonsense,
// and returning an error in a template function causes everything to
// stop rather ungracefully
values, err := url.ParseQuery(query)
if err != nil {
values = make(url.Values)
}
return values
}