table

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 7 Imported by: 3

README

table

Modified from github.com/modood/table.

Installation

$ go get github.com/404tk/table

Quick start

package main

import (
	"github.com/404tk/table"
)

type House struct {
	Name  string `table:"Name"`
	Sigil string
	Motto string
}

func main() {
	hs := []House{
		{"Stark", "direwolf", "Winter is coming"},
		{"Targaryen", "dragon", "Fire and Blood"},
		{"Lannister", "lion", "Hear Me Roar"},
	}

	// Output to stdout
	table.Output(hs)

	// Or just return table string and then do something
	s := table.Table(hs)
	_ = s
}

output:

+-----------+----------+------------------+
|   NAME    |  SIGIL   |      MOTTO       |
+-----------+----------+------------------+
| Stark     | direwolf | Winter is coming |
| Targaryen | dragon   | Fire and Blood   |
| Lannister | lion     | Hear Me Roar     |
+-----------+----------+------------------+

Documentation

Overview

Package table produces a string that represents slice of structs data in a text table

Example
package main

import (
	"github.com/404tk/table"
)

type House struct {
	Name  string
	Sigil string
	Motto string
}

func main() {
	hs := []House{
		{"Stark", "direwolf", "Winter is coming"},
		{"Targaryen", "dragon", "Fire and Blood"},
		{"Lannister", "lion", "Hear Me Roar"},
	}

	// Output to stdout
	table.Output(hs)

	// Or just return table string and then do something
	s := table.Table(hs)
	_ = s

	// Output to file
	table.FileOutput("test.log", hs)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileOutput

func FileOutput(filename string, slice interface{})

func Output

func Output(slice interface{})

Output formats slice of structs data and writes to standard output.

func Table

func Table(slice interface{}) string

Table formats slice of structs data and returns the resulting string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL