Skip to content

Instantly share code, notes, and snippets.

@jgraham909
Created April 8, 2013 08:35
Show Gist options
  • Save jgraham909/5335201 to your computer and use it in GitHub Desktop.
Save jgraham909/5335201 to your computer and use it in GitHub Desktop.
golang template idea
package main
import "fmt"
import "bytes"
import "html"
func main() {
s := Widget("myWidget", "checkbox", map[string] string{"checked": "checked", "someattr": "Value"})
fmt.Println(s)
}
func Widget(n,t string, attr map[string]string) string {
var b bytes.Buffer
b.WriteString(fmt.Sprintf(`<input name="%s" type="%s" `, n, t))
for k, v := range attr {
b.WriteString(fmt.Sprintf(` %s="%s"`, k, html.EscapeString(v)))
}
b.WriteString(" />")
return b.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment