Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.0
  • Source
  • Go
  • Socket score

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 25 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc