This commit is contained in:
2024-10-21 09:34:38 +00:00
parent 78b8ebf5bf
commit c7e45139ec
9 changed files with 201 additions and 22 deletions

55
structs-practice/main.go Normal file
View File

@@ -0,0 +1,55 @@
package main
import (
"bufio"
"fmt"
"example.com/note/note"
"os"
"strings"
)
func main() {
title, content := getNoteData()
userNote, err := note.New(title, content)
if err != nil {
fmt.Println(err)
return
}
userNote.Display()
err = userNote.Save()
if err != nil {
fmt.Println("Saving the note failed")
return
}
fmt.Println("Saving the note succeeded!")
}
func getNoteData() (string, string) {
title := getUserInput("Note title:")
content := getUserInput("Note content:")
return title, content
}
func getUserInput(prompt string) (string) {
fmt.Printf("%v ", prompt)
reader := bufio.NewReader(os.Stdin)
text, err :=reader.ReadString('\n')
if err != nil {
return ""
}
text = strings.TrimSuffix(text, "\n")
text = strings.TrimSuffix(text, "\r")
return text
}