--- /dev/null
+package main
+
+import (
+ "fmt"
+ "log"
+ "database/sql"
+ _ "github.com/mattn/go-sqlite3"
+)
+
+type column struct {
+ name string
+ title string
+ align int
+}
+
+type grid struct {
+ cols []column
+}
+
+func (g *grid) addColumn (c column) {
+ g.cols = append(g.cols, c)
+}
+
+func (g *grid) getHeader () string {
+ header := "<tr>\n"
+
+ for i, v := range g.cols {
+ header += fmt.Sprintf("\t<th>%s</th>\n", v.title)
+ fmt.Println(i, v)
+ }
+
+ header += "</tr>\n"
+
+ return header
+}
+
+func (g *grid) getRowFromDb (m map[string]interface{}) string {
+ ret := "<tr>\n"
+
+ for _, c := range g.cols {
+ ret += fmt.Sprintf("\t<td>%v</td>\n", m[c.name])
+ }
+
+ ret += "</tr>\n"
+
+ return ret
+}
+
+func main() {
+ var g grid
+
+ c := column{name: "id", title: "ID"}
+ g.addColumn(c)
+
+ c = column{name: "name", title: "Name"}
+ g.addColumn(c)
+
+ c = column{name: "surname", title: "Surname"}
+ g.addColumn(c)
+
+ c = column{name: "age", title: "Age"}
+ g.addColumn(c)
+
+ fmt.Println (g)
+
+ header := g.getHeader()
+
+ fmt.Println(header)
+
+ db, err := sql.Open("sqlite3", "./grid.db")
+ if err != nil {
+ // handle err
+ log.Fatal(err)
+ }
+
+ rows, err := db.Query("SELECT * FROM clients")
+ if err != nil {
+ // handle err
+ log.Fatal(err)
+ }
+ cols, err := rows.Columns()
+ if err != nil {
+ // handle err
+ log.Fatal(err)
+ }
+
+ fmt.Println(cols)
+
+ columns := make([]interface{}, len(cols))
+ columnPointers := make([]interface{}, len(cols))
+ for i, _ := range columns {
+ columnPointers[i] = &columns[i]
+ }
+
+ for rows.Next() {
+ err = rows.Scan(columnPointers...)
+ fmt.Println(columnPointers)
+
+ m := make(map[string]interface{})
+ for i, colName := range cols {
+ val := columnPointers[i].(*interface{})
+ m[colName] = *val
+ }
+
+ fmt.Println(m)
+
+ fmt.Println(g.getRowFromDb(m))
+ }
+}