Updating dependencies and fixing lint issues

This commit is contained in:
Julien Neuhart
2020-05-01 14:22:42 +02:00
parent edc5402aad
commit 42e357341a
18 changed files with 126 additions and 133 deletions

View File

@@ -132,21 +132,21 @@ func isViable(logger xlog.Logger) bool {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
endpoint := "http://localhost:9222"
logger.DebugfOp(
logger.DebugOpf(
op,
"checking Google Chrome headless process viability via endpoint '%s/json/version'",
endpoint,
)
v, err := devtool.New(endpoint).Version(ctx)
if err != nil {
logger.DebugfOp(
logger.DebugOpf(
op,
"Google Chrome headless is not viable as endpoint returned '%v'",
err.Error(),
)
return false
}
logger.DebugfOp(
logger.DebugOpf(
op,
"Google Chrome headless is viable as endpoint returned '%v'",
v,
@@ -162,9 +162,12 @@ func isViable(logger xlog.Logger) bool {
}
func warmup(logger xlog.Logger) {
const op string = "chrome.warmup"
warmupTime := xtime.Duration(0.5)
logger.DebugfOp(
const (
op string = "chrome.warmup"
seconds float64 = 0.5
)
warmupTime := xtime.Duration(seconds)
logger.DebugOpf(
op,
"waiting '%v' for allowing Google Chrome to warmup",
warmupTime,

View File

@@ -97,7 +97,8 @@ func (p chromePrinter) Print(destination string) error {
defer devtConn.Close() // nolint: errcheck
// create a new CDP Client that uses conn.
devtClient := cdp.NewClient(devtConn)
newContextTarget, err := devtClient.Target.CreateBrowserContext(ctx)
createBrowserContextArgs := target.NewCreateBrowserContextArgs()
newContextTarget, err := devtClient.Target.CreateBrowserContext(ctx, createBrowserContextArgs)
if err != nil {
return err
}
@@ -162,7 +163,7 @@ func (p chromePrinter) Print(destination string) error {
// apply a wait delay (if any).
if p.opts.WaitDelay > 0.0 {
// wait for a given amount of time (useful for javascript delay).
p.logger.DebugfOp(op, "applying a wait delay of '%.2fs'...", p.opts.WaitDelay)
p.logger.DebugOpf(op, "applying a wait delay of '%.2fs'...", p.opts.WaitDelay)
time.Sleep(xtime.Duration(p.opts.WaitDelay))
} else {
p.logger.DebugOp(op, "no wait delay to apply, moving on...")
@@ -183,8 +184,8 @@ func (p chromePrinter) Print(destination string) error {
if p.opts.PageRanges != "" {
printToPdfArgs.SetPageRanges(p.opts.PageRanges)
}
// print the page to PDF.
print, err := targetClient.Page.PrintToPDF(
// printToPDF the page to PDF.
printToPDF, err := targetClient.Page.PrintToPDF(
ctx,
printToPdfArgs,
)
@@ -209,7 +210,7 @@ func (p chromePrinter) Print(destination string) error {
}
return err
}
if err := ioutil.WriteFile(destination, print.Data, 0644); err != nil {
if err := ioutil.WriteFile(destination, printToPDF.Data, 0600); err != nil {
return err
}
return nil
@@ -282,7 +283,7 @@ func (p chromePrinter) setCustomHTTPHeaders(ctx context.Context, client *cdp.Cli
// useless but for the logs.
for key, value := range p.opts.CustomHTTPHeaders {
customHTTPHeaders[key] = value
p.logger.DebugfOp(op, "set '%s' to custom HTTP header '%s'", value, key)
p.logger.DebugOpf(op, "set '%s' to custom HTTP header '%s'", value, key)
}
b, err := json.Marshal(customHTTPHeaders)
if err != nil {
@@ -357,7 +358,7 @@ func (p chromePrinter) listenEvents(ctx context.Context, client *cdp.Client) err
if err != nil {
return err
}
p.logger.DebugfOp(op, "event '%s' received", ev.Name)
p.logger.DebugOpf(op, "event '%s' received", ev.Name)
if ev.Name == networkIdleEventName {
break
}

View File

@@ -36,7 +36,7 @@ func NewMarkdownPrinter(logger xlog.Logger, fpath string, opts ChromePrinterOpti
baseFilename := xrand.Get()
dst := fmt.Sprintf("%s/%s.html", dirPath, baseFilename)
logger.DebugOp(op, "writing the HTML from previous conversion(s) into new file...")
if err := ioutil.WriteFile(dst, buffer.Bytes(), 0644); err != nil {
if err := ioutil.WriteFile(dst, buffer.Bytes(), 0600); err != nil {
return "", err
}
return fmt.Sprintf("file://%s", dst), nil

View File

@@ -57,7 +57,7 @@ func (p mergePrinter) Print(destination string) error {
}
// see https://github.com/thecodingmachine/gotenberg/issues/139.
sort.Strings(p.fpaths)
p.logger.DebugfOp(op, "merging '%v'...", p.fpaths)
p.logger.DebugOpf(op, "merging '%v'...", p.fpaths)
resolver := func() error {
var args []string
args = append(args, p.fpaths...)

View File

@@ -64,11 +64,11 @@ func (p officePrinter) Print(destination string) error {
for i, fpath := range p.fpaths {
baseFilename := xrand.Get()
tmpDest := fmt.Sprintf("%s/%d%s.pdf", dirPath, i, baseFilename)
p.logger.DebugfOp(op, "converting '%s' to PDF...", fpath)
p.logger.DebugOpf(op, "converting '%s' to PDF...", fpath)
if err := p.unoconv(ctx, fpath, tmpDest); err != nil {
return err
}
p.logger.DebugfOp(op, "'%s.pdf' created", baseFilename)
p.logger.DebugOpf(op, "'%s.pdf' created", baseFilename)
fpaths[i] = tmpDest
}
if len(fpaths) == 1 {

View File

@@ -12,5 +12,5 @@ type Printer interface {
func logOptions(logger xlog.Logger, opts interface{}) {
const op string = "printer.logOptions"
logger.DebugfOp(op, "options: %+v", opts)
logger.DebugOpf(op, "options: %+v", opts)
}

View File

@@ -14,7 +14,7 @@ import (
// times out after given seconds.
func WithTimeout(logger xlog.Logger, seconds float64) (context.Context, context.CancelFunc) {
const op string = "xcontext.WithTimeout"
logger.DebugfOp(op, "creating context with '%.2fs' of timeout...", seconds)
logger.DebugOpf(op, "creating context with '%.2fs' of timeout...", seconds)
return context.WithTimeout(context.Background(), xtime.Duration(seconds))
}

View File

@@ -84,11 +84,11 @@ func Run(ctx context.Context, logger xlog.Logger, binary string, args ...string)
}()
select {
case err := <-result:
logger.DebugfOp(op, "command '%s' finished", strings.Join(cmd.Args, " "))
logger.DebugOpf(op, "command '%s' finished", strings.Join(cmd.Args, " "))
kill()
return err
case <-ctx.Done():
logger.DebugfOp(op, "command '%s' failed to finish before context.Context deadline", strings.Join(cmd.Args, " "))
logger.DebugOpf(op, "command '%s' failed to finish before context.Context deadline", strings.Join(cmd.Args, " "))
kill()
return ctx.Err()
}
@@ -102,7 +102,7 @@ func Run(ctx context.Context, logger xlog.Logger, binary string, args ...string)
// LogBeforeExecute logs a command before its execution.
func LogBeforeExecute(logger xlog.Logger, cmd *exec.Cmd) {
const op string = "xexec.LogBeforeExecute"
logger.DebugfOp(op, "executing command: %s", strings.Join(cmd.Args, " "))
logger.DebugOpf(op, "executing command: %s", strings.Join(cmd.Args, " "))
}
func pipe(logger xlog.Logger, cmd *exec.Cmd) error {

View File

@@ -104,9 +104,9 @@ func (l Logger) DebugOp(op, message string) {
l.entry.WithField("op", op).Debug(message)
}
// DebugfOp logs a debug message for given
// DebugOpf logs a debug message for given
// logical operation and format.
func (l Logger) DebugfOp(op, format string, args ...interface{}) {
func (l Logger) DebugOpf(op, format string, args ...interface{}) {
l.entry.WithField("op", op).Debugf(format, args...)
}
@@ -116,9 +116,9 @@ func (l Logger) InfoOp(op, message string) {
l.entry.WithField("op", op).Info(message)
}
// InfofOp logs an info message for given
// InfoOpf logs an info message for given
// logical operation and format.
func (l Logger) InfofOp(op, format string, args ...interface{}) {
func (l Logger) InfoOpf(op, format string, args ...interface{}) {
l.entry.WithField("op", op).Infof(format, args...)
}
@@ -128,9 +128,9 @@ func (l Logger) ErrorOp(op string, err error) {
l.entry.WithField("op", op).Error(err.Error())
}
// ErrorfOp logs an error message for given
// ErrorOpf logs an error message for given
// logical operation and format.
func (l Logger) ErrorfOp(op, format string, args ...interface{}) {
func (l Logger) ErrorOpf(op, format string, args ...interface{}) {
l.entry.WithField("op", op).Errorf(format, args...)
}