Adding test file read and write

This commit is contained in:
awstin 2025-10-02 17:09:18 -04:00 committed by Awstin
parent 56d3e153cb
commit 2bf278c312
2 changed files with 32 additions and 4 deletions

32
galley.go Normal file
View file

@ -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
}

View file

@ -1,4 +0,0 @@
package main
func main() {
}