Synchronize save messages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
dc5784c33e
commit
c8da493a9d
29
file.go
29
file.go
|
@ -17,12 +17,25 @@ import (
|
||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type saveMessage struct {
|
||||||
|
p string
|
||||||
|
page Page
|
||||||
|
summary string
|
||||||
|
author string
|
||||||
|
}
|
||||||
|
|
||||||
type FilePages struct {
|
type FilePages struct {
|
||||||
dirname string
|
dirname string
|
||||||
|
saveC chan saveMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilePages(dirname string) PagesRepository {
|
func NewFilePages(dirname string) PagesRepository {
|
||||||
fp := &FilePages{dirname}
|
fp := &FilePages{dirname, make(chan saveMessage)}
|
||||||
|
go func () {
|
||||||
|
for msg := range fp.saveC {
|
||||||
|
fp.save(msg)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return fp
|
return fp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +75,16 @@ func (fp *FilePages) Get(title string) Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fp *FilePages) Save(p string, page Page, summary, author string) error {
|
func (fp *FilePages) Save(p string, page Page, summary, author string) error {
|
||||||
|
fp.saveC <- saveMessage{p, page, summary, author}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FilePages) save(msg saveMessage) error {
|
||||||
|
p := msg.p
|
||||||
|
page := msg.page
|
||||||
|
summary := msg.summary
|
||||||
|
author := msg.author
|
||||||
|
|
||||||
f, err := os.Create(filepath.Join(fp.dirname, strings.Replace(p, " ", "_", -1)))
|
f, err := os.Create(filepath.Join(fp.dirname, strings.Replace(p, " ", "_", -1)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -87,7 +110,9 @@ func (fp *FilePages) Save(p string, page Page, summary, author string) error {
|
||||||
return fmt.Errorf("while processing backrefs: %s", err)
|
return fmt.Errorf("while processing backrefs: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveWithGit(fp, p, summary, author)
|
err = saveWithGit(fp, p, summary, author)
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveWithGit(fp *FilePages, p string, summary, author string) error {
|
func saveWithGit(fp *FilePages, p string, summary, author string) error {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user