FSDB_GO

This package is the Fsdb IO library for the Go Language.

It is designed to generally follow the Perl API, but it also supports structure-specific unpackaging in an idomaticly Go way.

The package is still under development.

Current known limitations:

Known desired features:

Samples

Example function reading with a structure (from TestRedaerFuncWrapping):

    type classTable struct {
        Sid int `col:"sid"`
        Name string `col:"sname"`
    }
    
    func TestReaderFuncWrapping(t *testing.T) {
        in, err := fsdb.NewFsdbReader(os.Stdin)
        if err != nil {
            panic("TestReaderFuncWrapping: cannot open NewFsdbReader")
        }
    
        var ct classTable
        ioCtRFunc, err := in.MakeReadStructFunc(&ct, "col")
        if err != nil {
            panic("TestReaderFuncWrapping: MakeReadStructState failed")
        }
        for {
            err = ioCtRFunc(&ct)
            if err != nil {
                if err != io.EOF {
                    panic("error reading rows")
                }
                break
            }
            fmt.Println(i, ct.Sid, ct.Name)
        }
    }
    

Example function reading directly, see TestReader in fsdb_reader_test.go.

Example function writing from a structure (from ExampleFsdbWriter() in fsdb_writer_test.go):

    type classTableW struct {
        Sid int `col:"sid"`
        Name string `col:"sname"`
    }
    
    var sampleClassTable = []classTableW {
        classTableW { 1, "dave" },
        classTableW { 2, "john" },
        classTableW { 3, "sugata" },
        }
    
    func ExampleFsdbWriter() { //(t *testing.T) {
        out, err := fsdb.NewFsdbWriter(os.Stdout)
        if err != nil {
            panic("cannot open NewFsdbWriter")
        }
        out.SetFSCode("t")
        for _, col := range([]string{"sid", "sname"}) {
            if err = out.AddCol(col); err != nil {
                panic(fmt.Sprintf("error adding cols: %q", err))
            }
        }
        out.Finalize()
        for _, ct := range sampleClassTable {
            var row []string
            row = append(row, fmt.Sprintf("%v", ct.Sid), ct.Name)
            if err = out.WriteRow(row); err != nil {
                panic(fmt.Sprintf("error writing rows: %q", err))
            }
        }
        out.Close()
        // Output:
        // #fsdb -F t sid sname
        // 1    dave
        // 2    john
        // 3    sugata
    
    }

Details

FSDB_GO
Copyright (C) 2016-2017 by John Heidemann

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

A fully copy of that license is in the file COPYING.