/wiki.go
https://code.google.com/p/goblogger/ · Go · 34 lines · 28 code · 6 blank · 0 comment · 2 complexity · 35637cde658dc62f47f0b202e5e68749 MD5 · raw file
- package main
- import (
- "fmt"
- "io/ioutil"
- "os"
- )
- type Page struct {
- Title string
- Body []byte
- }
- func ( p *Page ) save() os.Error {
- fileName := p.Title + ".txt"
- return ioutil.WriteFile( fileName, p.Body, 0600 )
- }
- func loadPage( title string ) ( *Page, os.Error ) {
- fileName := title + ".txt"
- body, err := ioutil.ReadFile( fileName )
- if( nil != err ) {
- return nil, err
- }
- return &Page{ Title: title, Body: body }, nil
- }
- func main() {
- pageLocal := &Page{ Title: "TestPage", Body: []byte( "This a sample") }
- pageLocal.save()
- pageLoaded, _ := loadPage( "TestPage" )
- fmt.Println( string( pageLoaded.Body ) )
- }