Merge pull request #176 from ArkBriar/master

Fix link in 11.12
This commit is contained in:
无闻
2015-11-06 08:19:23 -05:00
5 changed files with 46 additions and 6 deletions

View File

@@ -287,7 +287,7 @@ type ReaderWriter struct {
稍微改变练习 11.9,允许 `mapFunc` 接收不定数量的 items。
**练习 11.13**[main_stack.gostack/stack_general.go](exercises/chapter_11/main_stack.go—stack/stack_general.go)
**练习 11.13**[main_stack.go](exercises/chapter_11/main_stack.go)—[stack/stack_general.go](exercises/chapter_11/stack/stack_general.go)
在练习 10.10 和 10.11 中我们开发了一些栈结构类型。但是它们被限制为某种固定的内建类型。现在用一个元素类型是 interface{}(空接口)的切片开发一个通用的栈类型。

View File

@@ -71,7 +71,7 @@ func main() {
// panic(err.Error())
}
fmt.Printf("%s\n", string(buf))
err = ioutil.WriteFile(outputFile, buf, 0x644)
err = ioutil.WriteFile(outputFile, buf, 0644) // oct, not hex
if err != nil {
panic(err. Error())
}

View File

@@ -14,7 +14,7 @@ func main() {
panic(err.Error())
}
fmt.Printf("%s\n", string(buf))
err = ioutil.WriteFile(outputFile, buf, 0x644)
err = ioutil.WriteFile(outputFile, buf, 0644) // oct, not hex
if err != nil {
panic(err.Error())
}

View File

@@ -0,0 +1,40 @@
// wiki_part1.go
package main
import (
"fmt"
"io/ioutil"
)
type Page struct {
Title string
Body []byte
}
func (this *Page) save() (err error) {
return ioutil.WriteFile(this.Title, this.Body, 0666)
}
func (this *Page) load(title string) (err error) {
this.Title = title
this.Body, err = ioutil.ReadFile(this.Title)
return err
}
func main() {
page := Page{
"Page.md",
[]byte("# Page\n## Section1\nThis is section1."),
}
page.save()
// load from Page.md
var new_page Page
new_page.load("Page.md")
fmt.Println(string(new_page.Body))
}
/* Output:
* # Page
* ## Section1
* This is section1.
*/