table

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 4 Imported by: 0

README

Table Parser Made With Go

Easily parse your cool table-style output data.

Example

package main

import (
	"fmt"
	"strings"
	
	"github.com/anilmisirlioglu/table-parser"
)

const input = `
REPOSITORY      TAG          IMAGE ID       CREATED         SIZE
foo             latest       cf508acd919c   26 hours ago    24.5MB
bar             latest       382715ecff56   2 months ago    705MB
baz             v2.3.5       cc88abbad18b   2 months ago    317MB
`

func main() {
	// Read the all table
	t := table.ReadAll(input)
	fmt.Printf("table header len: %d\n", len(t.Header.Cells))
	
	// With using Reader
	r := table.NewReader(strings.NewReader(input))
	fmt.Printf("table header len: %d\n", len(r.Header().Cells))
	for r.Next() {
		fmt.Printf("Row: %+v\n", r.Row())
	}
}

Roadmap

  • Table Writer
  • Optimize the Header parser algorithm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	Text  string
	Cells []HeaderCell
}

type HeaderCell

type HeaderCell struct {
	Key   string
	Index int
}

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(rd io.Reader) *Reader

func (*Reader) Header

func (r *Reader) Header() Header

func (*Reader) Next

func (r *Reader) Next() bool

func (*Reader) Row

func (r *Reader) Row() Row

type Row

type Row struct {
	Text  string
	Cells []RowCell
}

func (*Row) Cell added in v0.0.2

func (r *Row) Cell(index int) *RowCell

func (*Row) CellByName added in v0.0.2

func (r *Row) CellByName(s string) *RowCell

type RowCell

type RowCell struct {
	Value    string
	Relation string
}

type Table

type Table struct {
	Header Header
	Rows   []Row
}

func ReadAll

func ReadAll(s string) *Table

func (*Table) Row added in v0.0.2

func (t *Table) Row(index int) *Row

Jump to

Keyboard shortcuts

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