godoc for converter package + fixing typo in godoc of process package

This commit is contained in:
Julien Neuhart
2018-04-03 11:53:16 +02:00
parent ed41e3e966
commit e207247c4b
2 changed files with 10 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
// Package converter implements a solution for converting one or more files to PDF.
package converter
import (
@@ -12,17 +13,21 @@ import (
"github.com/satori/go.uuid"
)
// Converter handles conversion into PDF of files coming from a request.
type Converter struct {
files []*gfile.File
workingDir string
}
// NoFileToConvertError is raised when the converter has no file
// to convert.
type NoFileToConvertError struct{}
func (e *NoFileToConvertError) Error() string {
return "There is no file to convert"
}
// NewConverter instantiates a converter by parsing a request.
func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, error) {
c := &Converter{
workingDir: fmt.Sprintf("./%s/", uuid.NewV4().String()),
@@ -77,6 +82,9 @@ func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, e
return c, nil
}
// Convert converts its associated files to PDF. If more than one file,
// it will merge all of them into one unique PDF file.
// Returns the new file path or an error if something bad happened.
func (c *Converter) Convert() (string, error) {
var filesPaths []string
for _, f := range c.files {
@@ -104,6 +112,7 @@ func (c *Converter) Convert() (string, error) {
return path, nil
}
// Clear removes all file inside its working directory.
func (c *Converter) Clear() error {
if err := os.RemoveAll(c.workingDir); err != nil {
return err

View File

@@ -69,7 +69,7 @@ func Unconv(workingDir string, file *gfile.File) (string, error) {
return cmdData.ResultFilePath, nil
}
// mergeDAta will be applied to the data-driven template of the merge command.
// mergeData will be applied to the data-driven template of the merge command.
type mergeData struct {
FilesPaths []string
ResultFilePath string