gocitiesjson

package module
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: Unlicense Imports: 5 Imported by: 3

README

Multi languages binding for cities.json

[!NOTE]

It's used for geo related benchmarks, not for production usages.

For Swift, see cities-swift.

LICENSE

This project is open sourced under The Unlicense.

The dataset, cities.json, created by lutangar and is licensed under CC-BY-4.0 license.

Documentation

Overview

Package go-cities.json is Go's mirror for https://github.com/lutangar/cities.json with Go's embed support.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Cities []*City
)

Functions

func All added in v0.6.0

func All(shuffle bool) iter.Seq[*City]
Example
package main

import (
	"fmt"

	gocitiesjson "github.com/ringsaturn/go-cities.json"
)

func main() {
	c := 0
	for city := range gocitiesjson.All(false) {
		_ = city
		c++
	}
	fmt.Println(c > 10000)
}
Output:
true

func Filter added in v0.6.0

func Filter(fn func(*City) bool, shuffle bool) iter.Seq[*City]
Example
package main

import (
	"fmt"

	gocitiesjson "github.com/ringsaturn/go-cities.json"
)

func main() {
	c := 0

	bboxFilter := func(city *gocitiesjson.City) bool {
		return city.Lng > 0 && city.Lng < 10 && city.Lat > 0 && city.Lat < 10
	}
	for city := range gocitiesjson.Filter(bboxFilter, false) {
		_ = city
		c++
	}

	fmt.Println(c > 0)
}
Output:
true

Types

type City

type City struct {
	Country string  `json:"country"`
	Name    string  `json:"name"`
	Lat     float64 `json:"lat"`
	Lng     float64 `json:"lng"`
	Admin1  string  `json:"admin1"`
	Admin2  string  `json:"admin2"`
}

func Random added in v0.6.2

func Random() *City

Jump to

Keyboard shortcuts

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