Excellent day everybody, I am a beginner to Go and also am still finding out the ropes, presently I am dealing with problems while making modifications to a json data.
So I have a feature that essentially gets rid of a component from the piece. I am incapable to add the json data somewhere else other than at one area. The “Done” will constantly obtain published, any kind of tips on this? Thanks
func removeAppt( get rid of AppointmentsDetail) {
bookedAppointmentsData:= getBookedAppointmentsData()// Obtain the piece of information
for i:= 0; i < < len( bookedAppointmentsData); i++ {
bookedAppt:= bookedAppointmentsData[i]
// If suits input worth eliminates it from piece and also append to json.
if bookedAppt == get rid of {
bookedAppointmentsData = append( bookedAppointmentsData[:i], bookedAppointmentsData[i+1:] ...).
i--.
bytes, err:= json.MarshalIndent( bookedAppointmentsData, ""," ").
if err!= nil {
log.Fatalln( err).
}
_ = ioutil.WriteFile(" bookedAppointments.json", bytes, 0644).
fmt.println(" Done")// Constantly obtains published.
break.
}
}
}
It maintains be published due to the fact that it remains in the struct meaning, AppointmentsDetail. I believe you can establish the 'omitempty' flag. As an example
Done bool int json:", omitempty"
It is effectively locating the AppointmentDetail you intend to get rid of; you recognize that due to the fact that "Done" obtains published.
Is the data being developed? I would certainly inspect the returned worth from the ioutil.WriteFile phone call.