Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
github.com/pariz/gountries
Inspired by the countries gem for ruby.
Countries (ISO-3166-1), Country Subdivisions(ISO-3166-2), Currencies (ISO 4217), Geo Coordinates(ISO-6709) as well as translations, country borders and other stuff exposed as struct data.
All data is derived from the pariz/countries repo.
This is currently a work in progress, so things may change. More stuff will be added
go get github.com/pariz/gountries
package main
import (
"fmt"
"github.com/pariz/gountries"
)
func main() {
query := gountries.New()
/////////////////
// Find sweden //
/////////////////
sweden, _ := query.FindCountryByName("sweden")
// sweden, _ := query.FindCountryByAlpha("SE")
// sweden, _ := query.FindCountryByAlpha("SWE")
fmt.Println(sweden.Name.Common) // Output: Sweden
fmt.Println(sweden.Name.Official) // Output: Konungariket Sverige
fmt.Println(sweden.Translations["DEU"].Common) // Output: Schweden
fmt.Println(sweden.Translations["DEU"].Official) // Output: Königreich Schweden
}
package main
import (
"fmt"
"github.com/pariz/gountries"
)
func main() {
query := gountries.New()
////////////////////////////////////////////
// Find the bordering countries of Sweden //
////////////////////////////////////////////
sweden, _ := query.FindCountryByAlpha("SWE") // "SE" also works..
// Get the bordering countries of sweden
for _, country := range sweden.BorderingCountries() {
fmt.Println(country.Name.Common)
}
// Output:
// Finland
// Norway
////////////////////////////////////
// Find all subdivisons for Sweden //
////////////////////////////////////
subdivisions := sweden.SubDivisions()
for _, subdivision := range subdivisions {
fmt.Println(subdivision.Name)
}
// Output:
// Västerbottens län
// Uppsala län
// Södermanlands län
// Gotlands län
// Dalarnas län
// ...
//////////////////////////////////////////////////////////
// Find all countries bordering Germany and Switzerland //
//////////////////////////////////////////////////////////
countryQuery := gountries.Country{
Borders: []string{
"DEU",
"CHE",
},
}
countries := query.FindCountries(countryQuery)
for _, c := range countries {
fmt.Println(c.Name.Common)
}
// Output:
// Austria
// France
///////////////////////////////////////////////////////////////////
// Calculate distance between Sweden and Germany (in Kilometers) //
///////////////////////////////////////////////////////////////////
se, _ := query.FindCountryByAlpha("SWE")
de, _ := query.FindCountryByAlpha("DEU")
distance := gountries.MeasureDistanceHaversine(se, de)
//distance := MeasureDistancePythagoras(se, de)
fmt.Println(distance)
// Output:
// 1430.1937864547901
distance = gountries.CalculateHaversine(
se.Coordinates.MaxLatitude, se.Coordinates.MaxLongitude,
de.Coordinates.MinLatitude, de.Coordinates.MinLongitude)
fmt.Println(distance)
// Output:
// 2641.26145088825
}
The data in the data/yaml
subdirectory is embedded using go-bindata. Once you include this library in your project, you won't need to access the data directory. To add or update the data, make changes to the YAML files then run:
go-bindata -pkg gountries data/yaml/*
Has a pretty solid test coverage but is constantly improving.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.