golocation

package
v0.0.0-...-bf1bca9 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

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:
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
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

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func UI ¶

func UI() fyne.CanvasObject

Types ¶

type App ¶

type App struct {
	// contains filtered or unexported fields
}

App - This houses the unexported database, so that it wont be tampered with outside this packaage

func New ¶

func New() (*App, error)

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

func (*App) AllCities ¶

func (app *App) AllCities() ([]City, error)

AllCities - Function to return all the available cities

func (*App) AllCountries ¶

func (app *App) AllCountries() ([]Country, error)

AllCountries - Function to return the list of available countries.

func (*App) AllStates ¶

func (app *App) AllStates() ([]State, error)

AllStates - Function to return all the available states.

func (*App) GetCity ¶

func (app *App) GetCity(cityID int) (*City, error)

GetCity - function to retrieve the city information

func (*App) GetCountry ¶

func (app *App) GetCountry(countryID int) Country

GetCountry - function to retrieve the country details

func (*App) GetCountryStates ¶

func (app *App) GetCountryStates(countryID int) ([]State, error)

GetCountryStates - Function to retrieve the states related to a country

func (*App) GetState ¶

func (app *App) GetState(stateID int) (*State, error)

GetState - Function to retrieve the states information

func (*App) GetStateCites ¶

func (app *App) GetStateCites(stateID int) ([]City, error)

GetStateCites - function to retrieve the citites that are present within a state

type City ¶

type City struct {
	Id      int    `json:"id"`
	Name    string `json:"name"`
	StateId int    `json:"state_id"`
}

City - Struct for housing the city information

func (City) String ¶

func (c City) String() string

type Country ¶

type Country struct {
	Id        int    `json:"id"`
	Code      string `json:"code"`
	Name      string `json:"name"`
	Phonecode int    `json:"phonecode"`
}

Country - struct that contains the country information

func (Country) String ¶

func (c Country) String() string

type State ¶

type State struct {
	Id        int    `json:"id"`
	Name      string `json:"name"`
	CountryId int    `json:"country_id"`
}

State - struct for housing the state information

func (State) String ¶

func (c State) String() string

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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