lint: fix issues

This commit is contained in:
CrazyMax
2025-08-03 20:18:42 +02:00
parent 8aaf66da27
commit 0950570ff7
11 changed files with 52 additions and 39 deletions

View File

@@ -87,11 +87,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
q := u.Query()
u.RawQuery = q.Encode()
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), dataBuf)
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", u.String(), dataBuf)
if err != nil {
return err
}

View File

@@ -128,11 +128,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err
}
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), dataBuf)
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", u.String(), dataBuf)
if err != nil {
return err
}

View File

@@ -89,11 +89,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
q.Set("token", token)
u.RawQuery = q.Encode()
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), bytes.NewBuffer(jsonBody))
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", u.String(), bytes.NewBuffer(jsonBody))
if err != nil {
return err
}

View File

@@ -81,11 +81,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
q := u.Query()
u.RawQuery = q.Encode()
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), dataBuf)
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", u.String(), dataBuf)
if err != nil {
return err
}

View File

@@ -122,11 +122,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
}
u.Path = path.Join(u.Path, "api/v1/chat.postMessage")
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), dataBuf)
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", u.String(), dataBuf)
if err != nil {
return err
}

View File

@@ -9,6 +9,7 @@ import (
"github.com/crazy-max/diun/v4/internal/model"
"github.com/crazy-max/diun/v4/internal/msg"
"github.com/crazy-max/diun/v4/internal/notif/notifier"
"github.com/pkg/errors"
)
// Client represents an active signalrest notification object
@@ -62,11 +63,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err
}
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", c.cfg.Endpoint, bytes.NewBuffer(body))
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", c.cfg.Endpoint, bytes.NewBuffer(body))
if err != nil {
return err
}

View File

@@ -110,11 +110,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err
}
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(10)*time.Second)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, 10*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", webhookURL, bytes.NewBuffer(jsonBody))
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", webhookURL, bytes.NewBuffer(jsonBody))
if err != nil {
return err
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/crazy-max/diun/v4/internal/model"
"github.com/crazy-max/diun/v4/internal/msg"
"github.com/crazy-max/diun/v4/internal/notif/notifier"
"github.com/pkg/errors"
)
// Client represents an active webhook notification object
@@ -47,11 +48,12 @@ func (c *Client) Send(entry model.NotifEntry) error {
return err
}
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()
cancelCtx, cancel := context.WithCancelCause(context.Background())
timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, *c.cfg.Timeout, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent
defer func() { cancel(errors.WithStack(context.Canceled)) }()
req, err := http.NewRequestWithContext(ctx, "POST", c.cfg.Endpoint, bytes.NewBuffer(body))
hc := http.Client{}
req, err := http.NewRequestWithContext(timeoutCtx, "POST", c.cfg.Endpoint, bytes.NewBuffer(body))
if err != nil {
return err
}