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

@@ -239,13 +239,13 @@ func convert(ctx context.Context, p printer.Printer) error {
// and directly return the resulting PDF file
// or an error.
if !r.HasArg(resource.WebhookURLArgKey) {
logger.DebugfOp(op, "no '%s' found, converting synchronously", resource.WebhookURLArgKey)
logger.DebugOpf(op, "no '%s' found, converting synchronously", resource.WebhookURLArgKey)
return convertSync(ctx, p, filename, fpath)
}
// as a webhook URL has been given, we
// run the following lines in a goroutine so that
// it doesn't block.
logger.DebugfOp(op, "'%s' found, converting asynchronously", resource.WebhookURLArgKey)
logger.DebugOpf(op, "'%s' found, converting asynchronously", resource.WebhookURLArgKey)
return convertAsync(ctx, p, filename, fpath)
}
if err := resolver(); err != nil {
@@ -264,7 +264,7 @@ func convertSync(ctx context.Context, p printer.Printer, filename, fpath string)
return err
}
if !r.HasArg(resource.ResultFilenameArgKey) {
logger.DebugfOp(
logger.DebugOpf(
op,
"no '%s' found, using generated filename '%s'",
resource.RemoteURLArgKey,
@@ -275,7 +275,7 @@ func convertSync(ctx context.Context, p printer.Printer, filename, fpath string)
}
return nil
}
logger.DebugfOp(
logger.DebugOpf(
op,
"'%s' found, so not using generated filename",
resource.ResultFilenameArgKey,
@@ -321,7 +321,7 @@ func convertAsync(ctx context.Context, p printer.Printer, filename, fpath string
return
}
defer f.Close() // nolint: errcheck
logger.DebugfOp(
logger.DebugOpf(
op,
"preparing to send result file '%s' to '%s'...",
filename,
@@ -342,13 +342,13 @@ func convertAsync(ctx context.Context, p printer.Printer, filename, fpath string
if len(customHTTPHeaders) > 0 {
for key, value := range customHTTPHeaders {
req.Header.Set(key, value)
logger.DebugfOp(op, "set '%s' to custom HTTP header '%s'", value, key)
logger.DebugOpf(op, "set '%s' to custom HTTP header '%s'", value, key)
}
} else {
logger.DebugOp(op, "skipping custom HTTP headers as none have been provided...")
}
// send the result file.
logger.DebugfOp(
logger.DebugOpf(
op,
"sending result file '%s' to '%s'...",
filename,
@@ -361,7 +361,7 @@ func convertAsync(ctx context.Context, p printer.Printer, filename, fpath string
return
}
defer resp.Body.Close() // nolint: errcheck
logger.DebugfOp(
logger.DebugOpf(
op,
"result file '%s' sent to '%s'",
filename,

View File

@@ -167,14 +167,14 @@ func (ctx Context) LogRequestResult(err error, isDebug bool) error {
"bytes_out": bytesOut(resp),
}
if err != nil {
ctx.logger.WithFields(fields).ErrorfOp(op, "request failed")
ctx.logger.WithFields(fields).ErrorOpf(op, "request failed")
return err
}
if isDebug {
ctx.logger.WithFields(fields).DebugfOp(op, "request handled")
ctx.logger.WithFields(fields).DebugOpf(op, "request handled")
return nil
}
ctx.logger.WithFields(fields).InfofOp(op, "request handled")
ctx.logger.WithFields(fields).InfoOpf(op, "request handled")
return nil
}

View File

@@ -25,7 +25,7 @@ func (f file) write(in io.Reader) error {
return err
}
defer out.Close() // nolint: errcheck
if err := out.Chmod(0644); err != nil {
if err := out.Chmod(0600); err != nil {
return err
}
if _, err := io.Copy(out, in); err != nil {

View File

@@ -50,7 +50,7 @@ func New(logger xlog.Logger, directoryName string) (Resource, error) {
if err != nil {
return Resource{}, xerror.New(op, err)
}
logger.DebugfOp(op, "resource directory '%s' created", directoryName)
logger.DebugOpf(op, "resource directory '%s' created", directoryName)
return Resource{
logger: logger,
dirPath: dirPath,
@@ -65,13 +65,13 @@ func New(logger xlog.Logger, directoryName string) (Resource, error) {
func (r Resource) Close() error {
const op string = "resource.Resource.Close"
if _, err := os.Stat(r.dirPath); os.IsNotExist(err) {
r.logger.DebugfOp(op, "resource directory '%s' does not exist, nothing to remove", r.dirPath)
r.logger.DebugOpf(op, "resource directory '%s' does not exist, nothing to remove", r.dirPath)
return nil
}
if err := os.RemoveAll(r.dirPath); err != nil {
return xerror.New(op, err)
}
r.logger.DebugfOp(op, "resource directory '%s' removed", r.dirPath)
r.logger.DebugOpf(op, "resource directory '%s' removed", r.dirPath)
return nil
}
@@ -84,17 +84,17 @@ func (r *Resource) WithCustomHTTPHeader(key string, value string) {
if strings.Contains(canonicalKey, RemoteURLCustomHTTPHeaderCanonicalBaseKey) ||
strings.Contains(canonicalKey, WebhookURLCustomHTTPHeaderCanonicalBaseKey) {
r.customHeaders[canonicalKey] = value
r.logger.DebugfOp(op, "added '%s' with value '%s' to resource custom HTTP headers", canonicalKey, value)
r.logger.DebugOpf(op, "added '%s' with value '%s' to resource custom HTTP headers", canonicalKey, value)
return
}
r.logger.DebugfOp(op, "skipping '%s' as it is not a custom HTTP header...", canonicalKey)
r.logger.DebugOpf(op, "skipping '%s' as it is not a custom HTTP header...", canonicalKey)
}
// WithArg add a new argument to the Resource.
func (r *Resource) WithArg(key ArgKey, value string) {
const op string = "resource.Resource.WithArg"
r.args[key] = value
r.logger.DebugfOp(op, "added '%s' with value '%s' to resource args", key, value)
r.logger.DebugOpf(op, "added '%s' with value '%s' to resource args", key, value)
}
// WithFile add a new file to the Resource.
@@ -112,7 +112,7 @@ func (r *Resource) WithFile(filename string, in io.Reader) error {
return err
}
r.files[filename] = file
r.logger.DebugfOp(op, "resource file '%s' created", filename)
r.logger.DebugOpf(op, "resource file '%s' created", filename)
return nil
}
if err := resolver(); err != nil {

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...)
}