mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 12:42:16 +01:00
godoc for converter package + fixing typo in godoc of process package
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// Package converter implements a solution for converting one or more files to PDF.
|
||||||
package converter
|
package converter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -12,17 +13,21 @@ import (
|
|||||||
"github.com/satori/go.uuid"
|
"github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Converter handles conversion into PDF of files coming from a request.
|
||||||
type Converter struct {
|
type Converter struct {
|
||||||
files []*gfile.File
|
files []*gfile.File
|
||||||
workingDir string
|
workingDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoFileToConvertError is raised when the converter has no file
|
||||||
|
// to convert.
|
||||||
type NoFileToConvertError struct{}
|
type NoFileToConvertError struct{}
|
||||||
|
|
||||||
func (e *NoFileToConvertError) Error() string {
|
func (e *NoFileToConvertError) Error() string {
|
||||||
return "There is no file to convert"
|
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) {
|
func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, error) {
|
||||||
c := &Converter{
|
c := &Converter{
|
||||||
workingDir: fmt.Sprintf("./%s/", uuid.NewV4().String()),
|
workingDir: fmt.Sprintf("./%s/", uuid.NewV4().String()),
|
||||||
@@ -77,6 +82,9 @@ func NewConverter(r *http.Request, contentType ghttp.ContentType) (*Converter, e
|
|||||||
return c, nil
|
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) {
|
func (c *Converter) Convert() (string, error) {
|
||||||
var filesPaths []string
|
var filesPaths []string
|
||||||
for _, f := range c.files {
|
for _, f := range c.files {
|
||||||
@@ -104,6 +112,7 @@ func (c *Converter) Convert() (string, error) {
|
|||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear removes all file inside its working directory.
|
||||||
func (c *Converter) Clear() error {
|
func (c *Converter) Clear() error {
|
||||||
if err := os.RemoveAll(c.workingDir); err != nil {
|
if err := os.RemoveAll(c.workingDir); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func Unconv(workingDir string, file *gfile.File) (string, error) {
|
|||||||
return cmdData.ResultFilePath, nil
|
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 {
|
type mergeData struct {
|
||||||
FilesPaths []string
|
FilesPaths []string
|
||||||
ResultFilePath string
|
ResultFilePath string
|
||||||
|
|||||||
Reference in New Issue
Block a user