-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (65 loc) · 1.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"bufio"
"fmt"
"os"
"slices"
"strconv"
"strings"
)
type TODOs struct {
Id int `json:"id"`
Description string `json:"description"`
Status bool `json:"status"`
}
func main() {
counter := 0
data := make([]TODOs, 0)
scanner := bufio.NewScanner(os.Stdin)
fmt.Print("CMDs: show create remove done\n")
for scanner.Scan() {
line := scanner.Text()
split := strings.Split(line, " ")
switch split[0] {
case "create":
data = append(data, TODOs{
Id: counter,
Description: strings.Join(split[1:], " "),
Status: false,
})
counter++
fmt.Println("Created TODO item")
case "remove":
index, err := strconv.Atoi(split[1])
if err != nil {
panic(err)
}
for i, todo := range data {
if todo.Id == index {
data = slices.Delete(data, i, i+1)
}
break
}
case "show":
for _, todo := range data {
fmt.Println("-----")
statusLine := "[]"
if todo.Status == true {
statusLine = "[x]"
}
fmt.Println(statusLine, todo.Description, "ID:", todo.Id)
}
case "done":
index, err := strconv.Atoi(split[1])
if err != nil {
panic(err)
}
for i, todo := range data {
if todo.Id == index {
data[i].Status = true
}
}
}
fmt.Print(">")
}
}