package templates import ( "html/template" ) type Field struct { Label string Name string Error string Type string Value string Placeholder string Valid bool } func (f *Field) init() { if f.Type == "" { f.Type = "text" } f.Valid = f.Valid || f.Error == "" } type Form struct { Action string Method string Fields []Field } func (f Form) HTML() template.HTML { if f.Method == "" { f.Method = "POST" } for i := range f.Fields { f.Fields[i].init() } return Tmpls.HTML("form.tmpl.html", f) }