View on GitHub

urban-wombat.github.io

For HTML API reference.

Struct Syntax Details

The Struct syntax is both flexible and strict.

Flexible

A struct need not have ANY data

[HitchhikersGuide]
name string
answer int
universe bool

Note: A struct table will remember that it has a struct shape.

If it has either

then the *gotables.Table.String() method will return a struct-shaped table.

A struct shaped table with one row of data:

[HitchhikersGuide]
name string   = "Arthur Dent"
answer int    = 42
universe bool = true

But if you were to increase the number of rows of data (programatically) to more than one row, the *gotables.Table.String() method will return a table-shaped table.

[HitchhikersGuide]
name           answer  universe
string         int     bool
"Arthur Dent"  42      true
"Ford Prefect" 44      true

Reduce it to one or less, and it will once again return a struct-shaped table.

[HitchhikersGuide]
name string   = "Arthur Dent"
answer int    = 42
universe bool = true

Remember, there is no semantic difference between a table-shaped table and a struct-shaped table. It’s rows all the way down …

A struct need not have ANY columns

[planets]

The table name without a table body may look lonely, but when instantiated in a program it will create a new *gotables.Table object (with the name planets in this case) ready for you to append columns and rows.

See example of how to instantiate a *gotables.Table struct syntax from a string

Strict

A struct must have BOTH column names AND column types or NEITHER

You cannot have a column name without a column type, or a column type without a column name.

A struct is terminated by a blank line or end of input