From 2bf278c312a2558c04ac364716f74fb4f936c9ba Mon Sep 17 00:00:00 2001 From: awstin Date: Thu, 2 Oct 2025 17:09:18 -0400 Subject: [PATCH] Adding test file read and write --- galley.go | 32 ++++++++++++++++++++++++++++++++ main.go | 4 ---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 galley.go delete mode 100644 main.go diff --git a/galley.go b/galley.go new file mode 100644 index 0000000..6de2db2 --- /dev/null +++ b/galley.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + p1 := &Page{Title: "TestPage", Body: []byte("This is a sample page.")} + p1.save() + p2, _ := loadPage("TestPage") + fmt.Println(string(p2.Body)) +} + +type Page struct { + Title string + Body []byte +} + +func (p *Page) save() error { + filename := p.Title + ".txt" + return os.WriteFile(filename, p.Body, 0600) +} + +func loadPage(title string) (*Page, error) { + filename := title + ".txt" + body, err := os.ReadFile(filename) + if err != nil { + return nil, err + } + return &Page{Title: title, Body: body}, nil +} diff --git a/main.go b/main.go deleted file mode 100644 index da29a2c..0000000 --- a/main.go +++ /dev/null @@ -1,4 +0,0 @@ -package main - -func main() { -}