Documentation ¶
Index ¶
- Variables
- type NotFoundError
- type Templates
- func (t *Templates) Compile(template string, data interface{}) (*bytes.Buffer, error)
- func (t *Templates) DefinedTemplates() (out string)
- func (t *Templates) Funcs(functions template.FuncMap) *Templates
- func (t *Templates) Render(w http.ResponseWriter, template string, data interface{}, status int) error
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultFunctions = template.FuncMap{ "title": strings.Title, "upper": strings.ToUpper, "lower": strings.ToLower, "trim": strings.TrimSpace, "urlencode": url.QueryEscape, "yesno": func(yes string, no string, value bool) string { if value { return yes } return no }, "plural": func(one, many string, count int) string { if count == 1 { return one } return many }, "date": func() string { return time.Now().Format("2006-01-02") }, "unixtimestamp": func() string { return fmt.Sprintf("%d", time.Now().Unix()) }, "json": func(v interface{}) string { output, _ := json.Marshal(v) return string(output) }, "noescape": func(a ...interface{}) template.HTML { return template.HTML(fmt.Sprint(a...)) }, "noescapeurl": func(u string) template.URL { return template.URL(u) }, "sha256": func(input string) string { hash := sha256.Sum256([]byte(input)) return hex.EncodeToString(hash[:]) }, "sha1": func(input string) string { hash := sha1.Sum([]byte(input)) return hex.EncodeToString(hash[:]) }, "md5": func(input string) string { hash := md5.Sum([]byte(input)) return hex.EncodeToString(hash[:]) }, "base64encode": func(v string) string { return base64.StdEncoding.EncodeToString([]byte(v)) }, "base64decode": func(v string) string { data, err := base64.StdEncoding.DecodeString(v) if err != nil { return err.Error() } return string(data) }, "base32encode": func(v string) string { return base32.StdEncoding.EncodeToString([]byte(v)) }, "base32decode": func(v string) string { data, err := base32.StdEncoding.DecodeString(v) if err != nil { return err.Error() } return string(data) }, }
DefaultFunctions for templates
Functions ¶
This section is empty.
Types ¶
type NotFoundError ¶
type NotFoundError struct {
Name string
}
NotFoundError for type assertions in the caller while still providing context
func (*NotFoundError) Error ¶
func (t *NotFoundError) Error() string
type Templates ¶
Templates Collection
func (*Templates) Compile ¶
Compile the template and return the buffer containing the rendered bytes
func (*Templates) DefinedTemplates ¶
DefinedTemplates loaded by got (for debugging)
Click to show internal directories.
Click to hide internal directories.