This Package offers a simple way to get Countries, Cities and States that you may need for your Application, most especially for location dropdown.
Install this Package by running:
go get github.com/ichtrojan/go-location
import "github.com/ichtrojan/go-location"
This package will return the output in structs
, you can manipulate the output however you choose. You can check the main.go
file located in the example
directory, the sample code in there returns the output as JSON
to the web.
- Clone this repo:
git clone github.com/ichtrojan/go-location
- Change directory to example folder:
cd go-location/example
- Run the application:
go run main.go
- Visit application:
Endpoint | Description |
---|---|
/country |
return all countries |
/country/{id} |
return a single country by its ID |
/state |
return all states |
/state/{id} |
return a single state by its ID |
/states/{countryID} |
return all states in a country using the country ID |
/city |
return all cities |
/city/{id} |
return a single city by its ID |
/cities |
return all cities in a state using the state ID |
golocation.AllCountries()
golocation.GetCountry(id)
NOTE
id
refers to the country ID
golocation.AllStates()
golocation.GetState(id)
NOTE
id
refers to the state ID
golocation.GetCountryStates(id)
NOTE
id
refers to the country ID
golocation.GetCities()
golocation.GetCity(id)
NOTE
id
refers to the city ID
golocation.GetStateCites(id)
NOTE
id
refers to the state ID
Free for all, if you find an issue with the package or if a group of people somehow created a new country please send in a PR.
Danke Schön