package http import "net/url" import "net/http" import "html/template" import "git.tebibyte.media/sashakoshka/step" import shttp "git.tebibyte.media/sashakoshka/step/http" var _ step.FuncProvider = new(Provider) // Provider provides HTTP and URL functions. type Provider struct { } // Package fulfills the step.Provider interface. func (this *Provider) Package () string { return "http" } // FuncMap fulfills the step.FuncProvider interface. func (this *Provider) FuncMap () template.FuncMap { return template.FuncMap { "statusText": http.StatusText, "parseQuery": funcParseQuery, "parseForm": funcParseForm, "error": funcError, "redirect": funcRedirect, "queryEscape": url.QueryEscape, "queryUnescape": url.QueryUnescape, } } 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 funcError (status int, message any) (string, error) { return "", shttp.Error { Status: status, Message: message, } } func funcRedirect (status int, pat string) (string, error) { return "", shttp.Redirect { Status: status, Location: pat, } } func funcParseForm (req *http.Request) url.Values { err := req.ParseForm() if err != nil { return nil } return req.Form }