You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Todo struct {
|
|
|
|
Title string
|
|
|
|
Content string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Todos struct {
|
|
|
|
Items []Todo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (todo *Todos) AddTodo(newTodo Todo) {
|
|
|
|
todo.Items = append(todo.Items, newTodo)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (todo *Todos) RemoveTodo(index int) (err error) {
|
|
|
|
//remove todo via index
|
|
|
|
if len(todo.Items) == 0 {
|
|
|
|
return errors.New("[ERR] Todo list is empty!\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
if index > len(todo.Items) {
|
|
|
|
return errors.New("[ERR] Index out of bounds\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
todo.Items = append(todo.Items[:index], todo.Items[index+1:]...)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (todo *Todos) ListTodo() int {
|
|
|
|
if len(todo.Items) == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
for k, v := range todo.Items {
|
|
|
|
fmt.Printf("%d:%s\n", k, v)
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
}
|