2010-04-27 20:36:39 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2011-01-25 21:56:52 -07:00
|
|
|
type Page struct {
|
|
|
|
Title string
|
|
|
|
Body []byte
|
2010-04-27 20:36:39 -06:00
|
|
|
}
|
|
|
|
|
2011-01-25 21:56:52 -07:00
|
|
|
func (p *Page) save() os.Error {
|
|
|
|
filename := p.Title + ".txt"
|
|
|
|
return ioutil.WriteFile(filename, p.Body, 0600)
|
2010-04-27 20:36:39 -06:00
|
|
|
}
|
|
|
|
|
2011-01-25 21:56:52 -07:00
|
|
|
func loadPage(title string) *Page {
|
2010-04-27 20:36:39 -06:00
|
|
|
filename := title + ".txt"
|
|
|
|
body, _ := ioutil.ReadFile(filename)
|
2011-01-25 21:56:52 -07:00
|
|
|
return &Page{Title: title, Body: body}
|
2010-04-27 20:36:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2011-01-25 21:56:52 -07:00
|
|
|
p1 := &Page{Title: "TestPage", Body: []byte("This is a sample page.")}
|
2010-04-27 20:36:39 -06:00
|
|
|
p1.save()
|
|
|
|
p2 := loadPage("TestPage")
|
2011-01-25 21:56:52 -07:00
|
|
|
fmt.Println(string(p2.Body))
|
2010-04-27 20:36:39 -06:00
|
|
|
}
|