diff options
Diffstat (limited to 'doc/codelab/wiki/part1-noerror.go')
-rw-r--r-- | doc/codelab/wiki/part1-noerror.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/codelab/wiki/part1-noerror.go b/doc/codelab/wiki/part1-noerror.go new file mode 100644 index 000000000..39e8331e3 --- /dev/null +++ b/doc/codelab/wiki/part1-noerror.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" +) + +type page struct { + title string + body []byte +} + +func (p *page) save() os.Error { + filename := p.title + ".txt" + return ioutil.WriteFile(filename, p.body, 0600) +} + +func loadPage(title string) *page { + filename := title + ".txt" + body, _ := ioutil.ReadFile(filename) + return &page{title: title, body: body} +} + +func main() { + p1 := &page{title: "TestPage", body: []byte("This is a sample page.")} + p1.save() + p2 := loadPage("TestPage") + fmt.Println(string(p2.body)) +} |