import (
"fmt"
"log"
+ "bytes"
+ "text/template"
+
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
toCall missingCol
}
+var headerTmpl = "<tr>\n{{ . }}</tr>\n"
+
type grid struct {
cols []column
+ headerTmpl string
}
func (g *grid) addColumn (c column) {
}
func (g *grid) getHeader () string {
- header := "<tr>\n"
+ tmpl := g.headerTmpl
+ if tmpl == "" {
+ tmpl = headerTmpl
+ }
+
+ t, err := template.New("header").Parse(tmpl)
+ if err != nil {
+ fmt.Println(err)
+ return ""
+ }
+
+ header := ""
for i, v := range g.cols {
header += fmt.Sprintf("\t<th>%s</th>\n", v.title)
fmt.Println(i, v)
}
- header += "</tr>\n"
+ var b bytes.Buffer
+ err = t.Execute(&b, header)
+ if err != nil {
+ fmt.Println(err)
+ return ""
+ }
- return header
+ return b.String()
}
func (g *grid) getRowFromMap (m map[string]interface{}) string {
func main() {
var g grid
+ g.headerTmpl = "<thead><tr>\n{{ . }}</tr></thead>\n"
+
c := column{name: "id", title: "ID"}
g.addColumn(c)