location

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 8 Imported by: 0

README

togo

togo-framework/location

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/location

location — localization dataset for togo

A togo plugin that ships a localization dataset — countries (ISO 3166-1 + currency + dial code + a representative timezone), languages (ISO 639-1), and IANA timezones — with lookup helpers and a REST API. An optional cities/areas dataset is loaded at runtime via location.LoadCities.

togo install togo-framework/location

REST API

Method Path
GET /api/location/countries
GET /api/location/countries/{code}
GET /api/location/countries/{code}/cities
GET /api/location/languages
GET /api/location/timezones

Go API

all := location.Countries()
eg, _ := location.CountryByCode("EG")      // {Code:EG, Currency:EGP, Dial:+20, Timezone:Africa/Cairo}
langs := location.Languages()
zones := location.Timezones()
// extend with your own cities/areas dataset:
location.LoadCities(map[string][]location.City{"EG": {{Name:"Cairo", Lat:30.04, Lng:31.23}}})
cairo := location.CitiesByCountry("EG")

The built-in set covers the common countries/languages/timezones and is extensible — append in a fork or load a richer cities/areas dataset via LoadCities.

MIT


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

Documentation

Overview

Package location is a togo plugin: a localization dataset — countries (ISO 3166-1 + currency + dial code + a representative timezone), languages (ISO 639-1), and IANA timezones — with lookup helpers and a REST API. An optional cities/areas dataset can be loaded at runtime via LoadCities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCities

func LoadCities(data map[string][]City)

LoadCities registers a cities dataset (country code → cities). Call from an app or a richer location-data plugin to extend the built-in dataset.

func Timezones

func Timezones() []string

Timezones returns the IANA timezone list.

Types

type City

type City struct {
	Name    string  `json:"name"`
	Country string  `json:"country"`
	Region  string  `json:"region"`
	Lat     float64 `json:"lat"`
	Lng     float64 `json:"lng"`
}

City is a place inside a country (loaded via LoadCities).

func CitiesByCountry

func CitiesByCountry(code string) []City

CitiesByCountry returns cities for a country code (empty unless LoadCities ran).

type Country

type Country struct {
	Code     string `json:"code"` // ISO 3166-1 alpha-2
	Name     string `json:"name"`
	Currency string `json:"currency"` // ISO 4217
	Dial     string `json:"dial"`     // E.164 calling code
	Region   string `json:"region"`
	Timezone string `json:"timezone"` // representative IANA zone
}

Country is an ISO 3166-1 country with currency, calling code and a default tz.

func Countries

func Countries() []Country

Countries returns all known countries (sorted by name).

func CountryByCode

func CountryByCode(code string) (Country, bool)

Country looks up a country by ISO 3166-1 alpha-2 code (case-insensitive).

type Language

type Language struct {
	Code   string `json:"code"`
	Name   string `json:"name"`
	Native string `json:"native"`
}

Language is an ISO 639-1 language.

func Languages

func Languages() []Language

Languages returns the ISO 639-1 language list.

Jump to

Keyboard shortcuts

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