Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
github.com/mmcloughlin/databundler
Embed CSV data as a Golang package.
go get github.com/mmcloughlin/databundler
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
Unknown package
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.