Por cierto, aqui les dejo mi codigo… soy muy visual y me gusta ver los mensajes!
package main
import "fmt"
type taskList struct {
tasks []*task
}
type task struct {
name string
description string
completed bool
}
func (t *taskList) addToList(tl *task) {
t.tasks = append(t.tasks, tl)
}
func (t *task) tagCompleted() {
t.completed = true
}
func (t *task) updateDescription(description string) {
t.description = description
}
func (t *task) updateName(name string) {
t.name = name
}
func (t *taskList) deleteFromList(index int) {
t.tasks = append(t.tasks[:index], t.tasks[index+1:]...)
}
func (t *taskList) printList() {
fmt.Println("------------------------------ LISTA DE TAREAS -----------------------------")
for _, task := range t.tasks {
fmt.Println("----------------------------------------------------------------------------")
fmt.Println(" ")
fmt.Println("Nombre: ", task.name)
fmt.Println(" ")
fmt.Println("Description: ", task.description)
fmt.Println(" ")
}
fmt.Println("----------------------------------------------------------------------------")
}
func (t *taskList) printListCompleted() {
fmt.Println("------------------------- LISTA DE TAREAS COMPLETADAS ----------------------")
for _, task := range t.tasks {
if task.completed {
fmt.Println("----------------------------------------------------------------------------")
fmt.Println(" ")
fmt.Println("Nombre: ", task.name)
fmt.Println(" ")
fmt.Println("Description: ", task.description)
fmt.Println(" ")
fmt.Println("Completed: ", task.completed)
fmt.Println(" ")
}
}
fmt.Println("----------------------------------------------------------------------------")
}
func main() {
t1 := &task{
name: "Complete my Go course",
description: "Complete my Go Course from Platzi in this week",
}
t2 := &task{
name: "Complete my Python course",
description: "Complete my Python Course from Platzi in this week",
completed: true,
}
t3 := &task{
name: "Complete my NodeJS course",
description: "Complete my NodeJS Course from Platzi in this week",
}
lista := &taskList{
tasks: []*task{
t1, t2,
},
}
lista.addToList(t3)
lista.printList()
lista.printListCompleted()
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?