Skip to content

Instantly share code, notes, and snippets.

@ilmiawan
Last active January 2, 2021 04:40
Show Gist options
  • Save ilmiawan/f0d1b8d221bce21d3e238f088de83b99 to your computer and use it in GitHub Desktop.
Save ilmiawan/f0d1b8d221bce21d3e238f088de83b99 to your computer and use it in GitHub Desktop.
contoh generic parameter
func GetCache(key string, result interface{}) {
res, err := cache.Get(key)
if err != nil {
log.Errorf("[ERROR] failed fetching cache: %v", err)
return
}
err = json.Unmarshal(res, result)
if err != nil {
log.Errorf("[ERROR] failed parsing cache : %v", err)
return
}
return
}
func GetListNegaraFromCache() []Negara {
result := make([]Negara, 0)
GetCache("negara", &result)
return result
}
func GetListProvinsiFromCache() []Provinsi {
result := make([]Provinsi, 0)
GetCache("provinsi", &result)
return result
}
func GetListKotaFromCache() []Kota {
result := make([]Kota, 0)
GetCache("kota", &result)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment