示例#1
0
文件: delete.go 项目: chooyan/todo
func Delete(id int) {
	scheduleList := util.ReadObj()

	newScheduleList := util.ScheduleList{scheduleList.MaxId, []util.Schedule{}}
	for i := 0; i < len(scheduleList.Schedules); i++ {
		if id != scheduleList.Schedules[i].Id {
			newScheduleList.Schedules = append(newScheduleList.Schedules, scheduleList.Schedules[i])
		}
	}

	scheduleJson, _ := json.Marshal(newScheduleList)
	util.Write(string(scheduleJson))
}
示例#2
0
文件: add.go 项目: chooyan/todo
// Add simply add single todo data with given title and deadline.
func Add(title string, deadline time.Time) {
	scheduleObjs := util.ReadObj()
	id := 0
	if len(scheduleObjs.Schedules) > 0 {
		id = scheduleObjs.MaxId + 1
	} else {
		scheduleObjs = util.ScheduleList{id, []util.Schedule{}}
	}
	now := time.Now()
	schedule := util.Schedule{id, title, now.Format(util.SaveTimeFormat), deadline.Format(util.SaveTimeFormat)}
	scheduleObjs.MaxId = id
	scheduleObjs.Schedules = append(scheduleObjs.Schedules, schedule)
	scheduleJson, _ := json.Marshal(scheduleObjs)

	util.Write(string(scheduleJson))
}