webhook: resulting file was deleted because of defer outside of goroutine

This commit is contained in:
Julien Neuhart
2018-12-13 18:15:28 +01:00
parent 404535c512
commit 4c1699df6c
6 changed files with 41 additions and 30 deletions

View File

@@ -8,35 +8,34 @@ import (
func convertMarkdown(c echo.Context) error {
r, err := newResource(c)
if err != nil {
return err
return hijackErr(err, r)
}
defer r.removeAll()
ctx, cancel := newContext(r)
if cancel != nil {
defer cancel()
}
indexPath, err := r.filePath("index.html")
if err != nil {
return err
return hijackErr(err, r)
}
p := &printer.Markdown{Context: ctx, TemplatePath: indexPath}
headerPath, _ := r.filePath("header.html")
if err := p.WithHeaderFile(headerPath); err != nil {
return err
return hijackErr(err, r)
}
footerPath, _ := r.filePath("footer.html")
if err := p.WithFooterFile(footerPath); err != nil {
return err
return hijackErr(err, r)
}
paperSize, err := r.paperSize()
if err != nil {
return err
return hijackErr(err, r)
}
p.PaperWidth = paperSize[0]
p.PaperHeight = paperSize[1]
paperMargins, err := r.paperMargins()
if err != nil {
return err
return hijackErr(err, r)
}
p.MarginTop = paperMargins[0]
p.MarginBottom = paperMargins[1]
@@ -44,7 +43,7 @@ func convertMarkdown(c echo.Context) error {
p.MarginRight = paperMargins[3]
landscape, err := r.landscape()
if err != nil {
return err
return hijackErr(err, r)
}
p.Landscape = landscape
return print(c, p, r)