databundler

command module
v0.0.0-...-eee1f60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2018 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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},
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址