Skip to content

Library Usage

guitarbum722 edited this page Sep 10, 2017 · 3 revisions

Library Usage examples

GoDoc

Create an Align

NewAlign creates and initializes a ScanWriter with in and out as its initial Reader and Writer and sets del to the desired delimiter to be used for alignment. It is meant to read the contents of its io.Reader to determine the length of each field and output the results in an aligned format. Left Justification is used by default. See UpdatePadding to set the Justification.

input := strings.NewReader("first,middle,last")
output := bytes.NewBufferString("")

aligner := align.NewAlign(input, output, ",", "\"") // io.Reader, io.Writer, input delimiter, text qualifier

Update the Padding Options if applicable

Use the PaddingOpts type to configure padding related output.

aligner.UpdatePadding(
    align.PaddingOpts{
            Justification:  align.JustifyCenter,
            ColumnOverride: map[int]Justification{
                2: align.JustifyRight,
                3: align.JustifyLeft,
            },
            Pad:            3, // default is 1
    }
)

Filter the output columns

aligner.FilterColumns([]int{3,4,7,10}]) // indexed starting with 1

Output delimiter / Separator

aligner.OutputSep("|")

Align the text

aligner.Align()

Clone this wiki locally