Inspired by Node MySchoolList
Library for fetching list of schools in Malaysia based on States & District.
Data taken from Ministry of Education Malaysia (Date release: January 2018)
Install this package using
go get github.com/svicknesh/myschoollist
Import it into your appliation
import "github.com/svicknesh/myschoollist"
There are no additional dependencies used by this package aside from what is available in Go standard.
The list_test.go
file contains examples of using this package.
The information about the states, districts and schools are in the json
folder which pulls the information from Node MySchoolList before cleaning it up a little. To rebuild the information, perform the following
cd json
go run import.go
list, err := myschoollist.New()
if nil != err {
log.Panic(err)
}
NOTE: Try not to instantiate too many instances of this list, instead instantiate it once and pass it to other modules or functions as parameters. Every instantiation loads the JSON information and creates mapping between them for quick lookup, which in turn uses memory. Having multiple instances MAY impact memory usage in long running applications for each instantiation.
stateID := 7
state, found := list.StateGetByID(stateID)
if !found {
log.Printf("State ID %d not found", stateID)
}
stateShortname := "pen" // case insensitive
state, found := list.StateGetByShortname(stateShortname)
if !found {
log.Printf("State ID %d not found", stateID)
}
states := list.StatesGetAll()
districtID := 73
district, found := list.DistrictGetByID(districtID)
if !found {
log.Printf("District ID %d not found", districtID)
}
schools := list.DistrictGetSchools(districtID)
districtID := 73
state, found = list.DistrictGetState(districtID)
if !found {
log.Printf("District ID %d not found", districtID)
}
schoolID := 9429
school, found := list.SchoolGetByID(schoolID)
if !found {
log.Printf("School ID %d not found", schoolID)
}
schoolCode := "peb1094"
school, found = list.SchoolGetByCode(schoolCode)
if !found {
log.Printf("School code %q not found", schoolCode)
}