Skip to content
Tabular data generator written in Go.
Go Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.golangci.yml
.travis.yml
LICENSE
Makefile
README.md
dataset.go
dataset_test.go
doc.go
go.mod
go.sum
header.go
row.go
row_test.go
set.go
sorter.go
tags.go
writer.go
writer_csv.go
writer_csv_test.go
writer_html.go
writer_html_test.go
writer_json.go
writer_json_test.go
writer_latex.go
writer_latex_test.go
writer_sql.go
writer_sql_test.go
writer_xml.go
writer_xml_test.go
writer_yaml.go
writer_yaml_test.go

README.md

tabular GoDoc Build Status Coverage Status

Tabular data generator written in Go.

Install

go get github.com/jbub/tabular

Docs

http://godoc.org/github.com/jbub/tabular

Example

package main

import (
    "log"
    "os"

    "github.com/jbub/tabular"
)

func main() {
    d := tabular.NewDataSet()
    d.AddHeader("firstname", "First name")
    d.AddHeader("lastname", "Last name")

    r1 := tabular.NewRow("Julia", "Roberts")
    r2 := tabular.NewRow("John", "Malkovich")
    err := d.Append(r1, r2)
    if err != nil {
        log.Fatal(err)
    }

    opts := &tabular.CSVOpts{
        Comma:   ';',
        UseCRLF: true,
    }
    csv := tabular.NewCSVWriter(opts)

    err = d.Write(csv, os.Stdout)
    if err != nil {
        log.Fatal(err)
    }
}

CSV

opts := &tabular.CSVOpts{
    Comma:   ';',
    UseCRLF: true,
}
csvw := tabular.NewCSVWriter(opts)

Output

Firstname;Lastname;Age
Julia;Roberts;40
John;Malkovich;42

HTML

opts := &tabular.HTMLOpts{
    Caption:    "Popular people",
    Indent:     2,
    TableClass: "",
    HeadClass:  "",
    RowClass:   "",
    DataClass:  "",
}
htmlw := tabular.NewHTMLWriter(opts)

Output

<table>
  <caption>Popular people</caption>
  <thead>
    <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Julia</td>
      <td>Roberts</td>
      <td>40</td>
    </tr>
    <tr>
      <td>John</td>
      <td>Malkovich</td>
      <td>42</td>
    </tr>
  </tbody>
</table>

JSON

opts := &tabular.JSONOpts{
    Indent: 4,
}
jsonw := tabular.NewJSONWriter(opts)

Output

[
    {
        "firstname": "Julia",
        "lastname": "Roberts",
        "age": "40"
    },
    {
        "firstname": "John",
        "lastname": "Malkovich",
        "age": "42"
    }
]

LaTeX

opts := &tabular.LatexOpts{
  Caption:  "",
  Center:   "",
  TabularX: false,
}
latexw := tabular.NewLatexWriter(opts)

Output

\begin{table}[h]
\begin{tabular}{|l|l|l|}
\hline
Firstname & Lastname  & Age \\ \hline
Julia     & Roberts   & 40  \\ \hline
John      & Malkovich & 42  \\ \hline
\end{tabular}
\end{table}

XML

opts := &tabular.XMLOpts{
    Indent:     4,
    RowElem:    "row",
    ParentElem: "rows",
}
xmlw := tabular.NewXMLWriter(opts)

Output

<rows>
    <row>
        <firstname>Julia</firstname>
        <lastname>Roberts</lastname>
        <age>40</age>
    </row>
    <row>
        <firstname>John</firstname>
        <lastname>Malkovich</lastname>
        <age>42</age>
    </row>
</rows>

YAML

opts := &tabular.YAMLOpts{}
yamlw := tabular.NewYAMLWriter(opts)

Output

- firstname: Julia
  lastname: Roberts
  age: 40
- firstname: John
  lastname: Malkovich
  age: 42

SQL

db, _ := sql.Open("postgres", "postgres://localhost/mydb?sslmode=disable")
opts := &tabular.SQLOpts{
    Driver: "postgres",
    DB:     db,
    Table: "my_table",
}
sqlw := tabular.NewSQLWriter(opts)

Output

SQL queries are performed in transaction, these are example queries:

BEGIN
INSERT INTO my_table (firstname,lastname,age) VALUES ($1,$2,$3)
INSERT INTO my_table (firstname,lastname,age) VALUES ($1,$2,$3)
COMMIT
You can’t perform that action at this time.