-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (72 loc) · 1.4 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
83
84
85
86
87
88
89
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/Med-IDBENOUAKRIM/notes/note"
"github.com/Med-IDBENOUAKRIM/notes/todo"
)
type saver interface {
Save() error
}
type outputtable interface {
saver
Display()
}
func main() {
title, content := getNoteData()
newNote, err := note.NewNote(title, content)
if err != nil {
fmt.Println(err)
return
}
text := getTodoData()
newTodo, err := todo.NewTodo(text)
if err != nil {
fmt.Println(err)
return
}
err = outputData(newNote)
if err != nil {
return
}
err = outputData(newTodo)
if err != nil {
return
}
}
func outputData(data outputtable) error {
data.Display()
return saveData(data)
}
func saveData(data saver) error {
err := data.Save()
if err != nil {
fmt.Println("Saving the note has error: ", err)
return err
}
fmt.Println("Saving the note succeeded!!")
return nil
}
func getTodoData() string {
text := getUserInputs("Please, enter your text:")
return text
}
func getNoteData() (string, string) {
title := getUserInputs("Please, enter your title:")
content := getUserInputs("Please, enter your content:")
return title, content
}
func getUserInputs(text string) string {
fmt.Println(text)
reader := bufio.NewReader(os.Stdin)
value, err := reader.ReadString('\n')
if err != nil {
fmt.Println(err)
return ""
}
value = strings.TrimSuffix(value, "\n")
value = strings.TrimSuffix(value, "\r")
return value
}