Skip to content

Commit d278e5d

Browse files
committed
jee32
1 parent a2c4939 commit d278e5d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

wiki.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2010 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"fmt"
9+
"io/ioutil"
10+
)
11+
12+
type Page struct {
13+
Title string
14+
Body []byte
15+
}
16+
17+
func (p *Page) save() error {
18+
filename := p.Title + ".txt"
19+
return ioutil.WriteFile(filename, p.Body, 0600)
20+
}
21+
22+
func loadPage(title string) (*Page, error) {
23+
filename := title + ".txt"
24+
body, err := ioutil.ReadFile(filename)
25+
if err != nil {
26+
return nil, err
27+
}
28+
return &Page{Title: title, Body: body}, nil
29+
}
30+
31+
func main() {
32+
p1 := &Page{Title: "TestPage", Body: []byte("This is a sample Page.")}
33+
p1.save()
34+
p2, _ := loadPage("TestPage")
35+
fmt.Println(string(p2.Body))
36+
}
37+

0 commit comments

Comments
 (0)