Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/mmcloughlin/databundler

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/mmcloughlin/databundler

  • v0.0.0-20180909113535-eee1f608751f
  • Source
  • Go
  • Socket score

Version published
Created
Source

databundler

Embed CSV data as a Golang package.

Install

go get github.com/mmcloughlin/databundler

Example

We'll use the Seven Summits as our example. The CSV we are going to embed into a package looks like

Mount Everest,8848,8848,Asia,Himalaya,Nepal/China,1953
Aconcagua,6961,6961,South America,Andes,Argentina,1897
Denali,6194,6144,North America,Alaska Range,United States,1913
Kilimanjaro,5895,5885,Africa,,Tanzania,1889
Mount Elbrus,5642,4741,Europe,Caucasus Mountains,Russia,1874
Mount Vinson,4892,4892,Antarctica,Sentinel Range,,1966
Puncak Jaya,4884,4884,Australasia,Sudirman Range,Indonesia,1962

We specify a schema in YAML format.

name: Peak
doc: Peak represents a mountain.
collection_doc: Peaks is the Messner version of the Seven Summits.
fields:
  - name: Name
    type: string
  - name: Elevation
    doc: Elevation in meters.
    type: int
  - null # ignore Prominence
  - name: Continent
    type: string
  - name: Range
    doc: Name of mountain range.
    type: string
  - name: Country
    type: string
  - name: FirstAscentYear
    type: int

Build the Go source with the following commands.

databundler -pkg sevensummits -data sevensummits.csv -schema schema.yaml -output sevensummits.go
gofmt -w sevensummits.go

Resulting in the following code.

// Generated code. DO NOT EDIT.

package sevensummits

// Peak represents a mountain.
type Peak struct {
	Name string
	// Elevation in meters.
	Elevation int
	Continent string
	// Name of mountain range.
	Range           string
	Country         string
	FirstAscentYear int
}

// Peaks is the Messner version of the Seven Summits.
var Peaks = []Peak{
	{"Mount Everest", 8848, "Asia", "Himalaya", "Nepal/China", 1953},
	{"Aconcagua", 6961, "South America", "Andes", "Argentina", 1897},
	{"Denali", 6194, "North America", "Alaska Range", "United States", 1913},
	{"Kilimanjaro", 5895, "Africa", "", "Tanzania", 1889},
	{"Mount Elbrus", 5642, "Europe", "Caucasus Mountains", "Russia", 1874},
	{"Mount Vinson", 4892, "Antarctica", "Sentinel Range", "", 1966},
	{"Puncak Jaya", 4884, "Australasia", "Sudirman Range", "Indonesia", 1962},
}

FAQs

Package last updated on 09 Sep 2018

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