PageRenderTime 98ms CodeModel.GetById 87ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/wiki.go

https://code.google.com/p/goblogger/
Go | 34 lines | 28 code | 6 blank | 0 comment | 2 complexity | 35637cde658dc62f47f0b202e5e68749 MD5 | raw file
 1package main
 2
 3import (
 4	"fmt"
 5	"io/ioutil"
 6	"os"	
 7)
 8
 9type Page struct {
10	Title string
11	Body []byte
12}
13
14func ( p *Page ) save() os.Error {
15	fileName := p.Title + ".txt"
16	return ioutil.WriteFile( fileName, p.Body, 0600 )
17}
18
19func loadPage( title string ) ( *Page, os.Error ) {
20	fileName := title + ".txt"
21	body, err := ioutil.ReadFile( fileName )
22    if( nil != err ) {
23        return nil, err
24    }
25    return  &Page{ Title: title, Body: body }, nil
26}
27
28func main() {
29	pageLocal := &Page{ Title: "TestPage", Body: []byte( "This a sample") }
30	pageLocal.save()
31
32	pageLoaded, _ := loadPage( "TestPage" )
33	fmt.Println( string( pageLoaded.Body )  )
34}