https://github.com/ichtrojan/go-location
A simple Go Package to sort Countries, States and Cities
https://github.com/ichtrojan/go-location
go golang location package
Last synced: 12 months ago
JSON representation
A simple Go Package to sort Countries, States and Cities
- Host: GitHub
- URL: https://github.com/ichtrojan/go-location
- Owner: ichtrojan
- Created: 2019-09-27T14:10:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T18:04:03.000Z (over 6 years ago)
- Last Synced: 2024-06-20T08:18:53.438Z (about 2 years ago)
- Topics: go, golang, location, package
- Language: Go
- Homepage:
- Size: 1.87 MB
- Stars: 43
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Go Location ▲

## Introduction 🖖
This Package offers a simple way to get Countries, Cities and States that you may need for your Application, most especially for location dropdown.
## Getting Started 💽
### Install Package
Install this Package by running:
```bash
go get github.com/ichtrojan/go-location
```
### Import Package
```go
import "github.com/ichtrojan/go-location"
```
## Usage 🧨
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.
### Demo
* 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|
### Package Methods
#### Get all countries
````go
golocation.AllCountries()
````
#### Get a Country
```go
golocation.GetCountry(id)
```
> **NOTE**
>`id` refers to the country ID
#### Get all states
```go
golocation.AllStates()
```
#### Get a state
```go
golocation.GetState(id)
```
> **NOTE**
>`id` refers to the state ID
#### Get all states in a country
```go
golocation.GetCountryStates(id)
```
> **NOTE**
>`id` refers to the country ID
#### Get all cities
```get
golocation.GetCities()
```
#### Get a city
```go
golocation.GetCity(id)
```
> **NOTE**
>`id` refers to the city ID
#### Get cities in a state
```go
golocation.GetStateCites(id)
```
> **NOTE**
>`id` refers to the state ID
## Contribution
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