2012-01-22 15:28:32 -07:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-11-14 12:32:24 -07:00
|
|
|
// +build ignore
|
|
|
|
|
2010-04-27 20:36:39 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
2011-01-25 21:56:52 -07:00
|
|
|
type Page struct {
|
|
|
|
Title string
|
|
|
|
Body []byte
|
2010-04-27 20:36:39 -06:00
|
|
|
}
|
|
|
|
|
2011-11-01 20:06:05 -06:00
|
|
|
func (p *Page) save() error {
|
2011-01-25 21:56:52 -07:00
|
|
|
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
|
|
|
}
|