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.
79 lines
1.3 KiB
79 lines
1.3 KiB
1 year ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"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) {
|
||
|
//remove todo via index
|
||
|
todo.Items = append(todo.Items[:index], todo.Items[index+1:]...)
|
||
|
}
|
||
|
|
||
|
func (todo *Todos) ListTodosFull() {
|
||
|
//List all the contents
|
||
|
if len(todo.Items) == 0 {
|
||
|
fmt.Printf("empty\n")
|
||
|
}
|
||
|
for k, v := range todo.Items {
|
||
|
fmt.Printf("%d:%s\n", k, v)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func ListTodosSmall() {
|
||
|
fmt.Println("ListTodosSmall func. not implemented")
|
||
|
//List all the contents
|
||
|
}
|
||
|
func main() {
|
||
|
fmt.Println("TODO APP")
|
||
|
|
||
|
list := Todos{}
|
||
|
//todos := []Todo{}
|
||
|
//list := Todos{todos}
|
||
|
fmt.Println("Empty list: ")
|
||
|
list.ListTodosFull()
|
||
|
|
||
|
fmt.Println("Adding entries...")
|
||
|
items := []Todo{
|
||
|
{
|
||
|
Title: "test",
|
||
|
Content: "Here is some content",
|
||
|
},
|
||
|
{
|
||
|
Title: "test1",
|
||
|
Content: "Here is some more content",
|
||
|
},
|
||
|
{
|
||
|
Title: "test2",
|
||
|
Content: "Here is even MORE content",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
//Add the items for testing
|
||
|
for item := range items {
|
||
|
list.AddTodo(items[item])
|
||
|
}
|
||
|
|
||
|
fmt.Println("Listing...")
|
||
|
list.ListTodosFull()
|
||
|
fmt.Println("Listing again...")
|
||
|
list.ListTodosFull()
|
||
|
|
||
|
fmt.Println("Removing item2 via index 1")
|
||
|
list.RemoveTodo(1)
|
||
|
fmt.Println("Listing again...")
|
||
|
list.ListTodosFull()
|
||
|
}
|