Skip to content

Commit

Permalink
Step-0 Bootstrapping
Browse files Browse the repository at this point in the history
- Create a gowiki.go file.
- Add the Page struct.
- Add the save and loadPage function.
- Write the main function to test what we've written.
  • Loading branch information
DehuaZhao committed Aug 18, 2017
1 parent 134f0d2 commit f29b152
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gowiki.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"fmt"
"io/ioutil"
)

// Page struct, containing Title and Body
type Page struct {
Title string
Body []byte
}

func (p *Page) save() 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))
}

0 comments on commit f29b152

Please sign in to comment.