-1
Ben bir yapı var ?dönüş türü ile aynı
Ben bir yapı var ?dönüş türü ile aynı
Sen unmarshal değişkene gösterici geçmek ve sadece değişken döndürebilir.
func LoadClass(path string) (race Race) {
bytes, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
if err = json.Unmarshal(bytes, &race); err != nil {
panic(err)
}
return
}
Evet, sadece *Race
yerine Race
bir değer döndürmek:
func LoadClass(path string) Race {
// read file to []byte
jsonClass := new(Race)
_ = json.Unmarshal(bytes, jsonClass)
// return the value jsonClass points to
return *jsonClass
}
Bu, aklımı darbeler, işlev bildirimi olarak adlandırılmış bir ad verebileceğimizi bilmiyordum – vutran