🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/sfomuseum/go-csvdict/v2

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/sfomuseum/go-csvdict/v2

v2.0.1
Source
Go
Version published
Created
Source

go-csvdict

Go package to implement a "dict reader" style CSV parser (on top of the default encoding/csv package) to return rows a key-value dictionaries rather than lists.

Documentation

Go Reference

Example

Reading files

import (
	"os"

        "github.com/whosonfirst/go-csvdict/v2"
)

r, _ := csvdict.NewReaderFromPath("example.csv")

// or maybe you might do
// r, _ := csvdict.NewReader(os.Stdin)

for {
	row, err := r.Read()

	if err == io.EOF {
		break
	}

	if err != nil {
		return err
	}

	value, ok := row["some-key"]
	// and so on...
}

It is also possible to iterate through all the records using the Iterate method:

import (
	"os"

        "github.com/whosonfirst/go-csvdict/v2"
)

r, _ := csvdict.NewReaderFromPath("example.csv")

// or maybe you might do
// r, _ := csvdict.NewReader(os.Stdin)

for row, err := r.Iterate() {

	if err != nil {
		return err
	}

	value, ok := row["some-key"]
	// and so on...
}

Writing files

import (
	"os"

	"github.com/whosonfirst/go-csvdict/v2"
)

wr, _ := csvdict.NewWriter(os.Stdout)

// or maybe you might do
// wrr, _ := csvdict.NewWriterFromPath("new.csv")

row := make(map[string]{
	"foo": "hello",
	"bar": "world",
}

wr.WriteRow(row)

See also

FAQs

Package last updated on 20 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts