Categorygithub.com/ichtrojan/go-location
modulepackage
1.0.0
Repository: https://github.com/ichtrojan/go-location.git
Documentation: pkg.go.dev

# README

Go Location ▲

banner

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:

go get github.com/ichtrojan/go-location

Import Package

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:
EndpointDescription
/countryreturn all countries
/country/{id}return a single country by its ID
/statereturn all states
/state/{id}return a single state by its ID
/states/{countryID}return all states in a country using the country ID
/cityreturn all cities
/city/{id}return a single city by its ID
/citiesreturn all cities in a state using the state ID

Package Methods

Get all countries

golocation.AllCountries()

Get a Country

golocation.GetCountry(id)

NOTE
id refers to the country ID

Get all states

golocation.AllStates()

Get a state

golocation.GetState(id)

NOTE
id refers to the state ID

Get all states in a country

golocation.GetCountryStates(id)

NOTE
id refers to the country ID

Get all cities

golocation.GetCities()

Get a city

golocation.GetCity(id)

NOTE
id refers to the city ID

Get cities in a state

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

# Packages

No description provided by the author

# Functions

New - Create a new instance of the go-location package.

# Structs

App - This houses the unexported database, so that it wont be tampered with outside this packaage.
City - Struct for housing the city information.
Country - struct that contains the country information.
State - struct for housing the state information.