This commit is contained in:
2024-10-23 12:10:32 +00:00
parent c7e45139ec
commit a8148f2400
8 changed files with 230 additions and 5 deletions

View File

@@ -0,0 +1,38 @@
package todo
import (
"encoding/json"
"errors"
"fmt"
"os"
)
type Todo struct {
Text string `json:"text"`
}
func (todo Todo) Display() {
fmt.Printf(todo.Text)
}
func (todo Todo) Save() error {
fileName := "todo.json"
json, err := json.Marshal(todo)
if err != nil {
return err
}
return os.WriteFile(fileName, json, 0644)
}
func New(content string) (Todo, error) {
if content == "" || content == "" {
return Todo{}, errors.New("Invalid input")
}
return Todo{
Text: content,
}, nil
}