Giter VIP home page Giter VIP logo

goltsv's Introduction

goltsv

LTSV (Labeled Tab Separeted Value) reader/writer for Go.

https://drone.io/github.com/ymotongpoo/goltsv/status.png

Example

Reader

package main

import (
     "bytes"
     "fmt"
     "github.com/ymotongpoo/goltsv"
)

func main() {
     data := `
egg:たまご      ham:ハム  bread:パン
gyoza:ぎょうざ   ramen:ラーメン      sushi:すし        yakiniku:焼肉
yamanashi:山梨 tokyo:東京        okinawa:沖縄      hokkaido:北海道
`
     b := bytes.NewBufferString(data)

     // Read LTSV file into map[string]string
     reader := goltsv.NewReader(b)
     records, err := reader.ReadAll()
     if err != nil {
             panic(err)
     }

     // dump
     for i, record := range records {
             fmt.Printf("===== Data %d\n", i)
             for k, v := range record {
                     fmt.Printf("\t%s --> %s\n", k, v)
             }
     }
}

Writer

package main

import (
     "bytes"
     "github.com/ymotongpoo/goltsv"
)

func main() {
     data := []map[string]string {
             {"Python": "3.3.0", "Ruby": "2.0 rc2", "Perl": "5.16.2"},
             {"spam": "foo", "egg": "bar", "ham": "buz"},
             {"sauce": "ソース", "salt": "しお", "sugar": "さとう", "vinegar": "す"},
     }

     b := &bytes.Buffer{}
     writer := goltsv.NewWriter(b)
     err := writer.WriteAll(data)
     if err != nil {
             panic(err)
     }
     fmt.Printf("%v", b.String())
}

License

This packages is distributed under conditions of New BSD License

goltsv's People

Contributors

mattn avatar ymotongpoo avatar koyachi avatar

Watchers

Taku Okawa avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.