-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (67 loc) · 1.44 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
73
74
75
76
77
78
79
80
81
82
package main
import (
// "log"
"bufio"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/aminoxix/todo-cli/cmd/handlers"
"github.com/aminoxix/todo-cli/shared/data"
// "github.com/aminoxix/todo-cli/shared/models"
// "github.com/gorilla/mux"
)
func main() {
// router := mux.NewRouter()
// router.HandleFunc("/", serveHome)
// log.Fatal(http.ListenAndServe(":8080", router))
// var todo models.Todo
// var id int
fmt.Printf(`
What operation do you want to perform?
c: Insert a todo
r: View all todos
u: Update a todo
d: Delete a todo
`)
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
log.Fatal("no input provided!")
}
formattedInput := strings.TrimSpace(input)
switch formattedInput {
case "c":
handlers.Insert()
case "r":
handlers.ViewAll()
case "u":
handlers.Update()
case "d":
handlers.Delete()
default:
panic("invalid input")
}
if formattedInput != "r" {
// create file
file, err := os.Create("./shared/data/todos.json")
if err != nil {
panic(err)
}
// for indentation
finalJson, err := json.MarshalIndent(data.Todos, "", "\t")
if err != nil {
panic(err)
}
// write file
os.WriteFile("./shared/data/todos.json", finalJson, 0644)
// file close
file.Close()
fmt.Println("writing todos file...", data.Todos)
}
}
func serveHome(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<h1>hey, this is a todo app</h1>"))
}