providers: Rename url provider to http
This commit is contained in:
37
providers/http/http.go
Normal file
37
providers/http/http.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package http
|
||||
|
||||
import "net/http"
|
||||
import "net/url"
|
||||
import "html/template"
|
||||
import "git.tebibyte.media/sashakoshka/step"
|
||||
|
||||
var _ step.FuncProvider = new(Provider)
|
||||
|
||||
// Provider provides HTTP and URL functions.
|
||||
type Provider struct {
|
||||
|
||||
}
|
||||
|
||||
// FuncMap fulfills the step.FuncProvider interface.
|
||||
func (this *Provider) FuncMap () template.FuncMap {
|
||||
return template.FuncMap {
|
||||
"parseQuery": funcParseQuery,
|
||||
"parseForm": funcParseForm,
|
||||
}
|
||||
}
|
||||
|
||||
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 { return nil }
|
||||
return values
|
||||
}
|
||||
|
||||
|
||||
func funcParseForm (req *http.Request) url.Values {
|
||||
err := req.ParseForm()
|
||||
if err != nil { return nil }
|
||||
return req.Form
|
||||
}
|
||||
Reference in New Issue
Block a user