inaarea

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 7 Imported by: 0

README

INA-Area

Generate Area in Indonesia (Offline) :)

Data

  • 34 Provinces
  • 499 Districts
  • 6878 Sub Districts
  • 79702 Urban Villages

Install

go get -u github.com/ariefsn/ina-area

Import

import ia "github.com/ariefsn/ina-area"

Model

type AreaModel struct {
  Code   string `json:"code"`
  Name   string `json:"name"`
  Parent string `json:"parent"`
}

API

  • Get Provinces

    // Will return slice provinces and total data
    data, _ := ia.GetProvinces(nil)
    
    fmt.Println(data[0]) // {11 Aceh }
    
    // With filter
    data, _ := ia.GetProvinces([]ia.AreaModel{
      {
        Code: "35",
      },
    })
    
    fmt.Println(data) // [{35 Jawa Timur }]
    
    // Find by code ==> if not found it will return nil
    data2 := ia.GetProvinceByCode("35")
    
    fmt.Println(data2) // &{35 Jawa Timur }
    
  • Get Districts

    // Will return slice districs and total data
    data, _ := ia.GetDistrics(nil)
    
    fmt.Println(data[0]) // {1101 Kab. Simeulue 11}
    
    // With filter
    data, _ := ia.GetDistricts([]ia.AreaModel{
      {
        Code: "3521",
      },
    })
    
    fmt.Println(data) // [{3521 Kab. Ngawi 35}]
    
    // Or find by specific province code
    data, _totalDist2_ := ia.GetDistrictsByProvince("35", []ia.AreaModel{
      {
        Name: "Ngawi",
      },
    })
    
    fmt.Println(data) // [{3521 Kab. Ngawi 35}]
    
    // Find by code ==> if not found it will return nil
    data2 := ia.GetDistrictByCode("3521")
    
    fmt.Println(data2) // &{3521 Kab. Ngawi 35}
    
  • Get Sub Districts

    // Will return slice sub districs and total data
    data, _ := ia.GetSubDistrics(nil)
    
    fmt.Println(data[0]) // {1101010 Teupah Selatan 1101}
    
    // With filter
    data, _ := ia.GetSubDistricts([]ia.AreaModel{
      {
        Code: "3521030",
      },
    })
    
    fmt.Println(data) // [{3521030 Jogorogo 3521}]
    
    // Or find by specific district code
    data, _totalDist2_ := ia.GetSubDistrictsByDistrict("3521", []ia.AreaModel{
      {
        Name: "Jogorogo",
      },
    })
    
    fmt.Println(data) // [{3521030 Jogorogo 3521}]
    
    // Find by code ==> if not found it will return nil
    data2 := ia.GetSubDistrictByCode("3521030")
    
    fmt.Println(data2) // &{3521030 Jogorogo 3521}
    
  • Get Urban Villages

    // Will return slice urban villages and total data
    data, _ := ia.GetUrbanVillages(nil)
    
    fmt.Println(data[0]) // {9104073001 Weriagar 9104073}
    
    // With filter
    data, _ := ia.GetUrbanVillages([]ia.AreaModel{
      {
        Code: "3521030009",
      },
    })
    
    fmt.Println(data) // [{3521030009 Jogorogo 3521030}]
    
    // Or find by specific sub district code
    data, _totalDist2_ := ia.GetUrbanVillagesBySubDistrict("3521", []ia.AreaModel{
      {
        Name: "Jogorogo",
      },
    })
    
    fmt.Println(data) // [{3521030009 Jogorogo 3521030}]
    
    
    // Find by code ==> if not found it will return nil
    data2 := ia.GeturbanVillageByCode("3521030009")
    
    fmt.Println(data2) // &{3521030009 Jogorogo 3521030}
    

Documentation

Index

Constants

View Source
const (
	PROVINCE     Area = "PROVINCE"
	DISTRICT          = "DISTRICT"
	SUBDISTRICT       = "SUBDISTRICT"
	URBANVILLAGE      = "URBANVILLAGE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Area

type Area string

type AreaModel

type AreaModel struct {
	Code   string `json:"code"`
	Name   string `json:"name"`
	Parent string `json:"parent"`
}

func GetDistrictByCode

func GetDistrictByCode(code string) *AreaModel

GetDistrictByCode find district by code

func GetDistricts

func GetDistricts(filters []AreaModel) ([]AreaModel, int)

GetDistricts generate district datas

func GetDistrictsByProvince

func GetDistrictsByProvince(provinceCode string, filters []AreaModel) ([]AreaModel, int)

GetDistrictsByProvince generate district by province code

func GetProvinceByCode

func GetProvinceByCode(code string) *AreaModel

GetProvinceByCode find province by code

func GetProvinces

func GetProvinces(filters []AreaModel) ([]AreaModel, int)

GetProvinces generate province datas

func GetSubDistrictByCode

func GetSubDistrictByCode(code string) *AreaModel

GetSubDistrictByCode find sub district by code

func GetSubDistricts

func GetSubDistricts(filters []AreaModel) ([]AreaModel, int)

GetSUbDistricts generate sub districts datas

func GetSubDistrictsByDistrict

func GetSubDistrictsByDistrict(districtCode string, filters []AreaModel) ([]AreaModel, int)

GetSubDistrictsByDistrict generate sub district by district code

func GetUrbanVillageByCode

func GetUrbanVillageByCode(code string) *AreaModel

GetUrbanVillageByCode find urban village by code

func GetUrbanVillages

func GetUrbanVillages(filters []AreaModel) ([]AreaModel, int)

GetUrbanVillages generate urban villages datas

func GetUrbanVillagesBySubDistrict

func GetUrbanVillagesBySubDistrict(subDistrictCode string, filters []AreaModel) ([]AreaModel, int)

GetUrbanVillageBySubDistrict generate urban village by sub district code

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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