Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Dec 20, 2024
1 parent bda2b75 commit 4635752
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

meta.Version = version
meta.UserAgent = fmt.Sprintf("%s/%s go/%s %s", meta.ID, meta.Version, runtime.Version()[2:], strings.Title(runtime.GOOS))
meta.UserAgent = fmt.Sprintf("%s/%s go/%s %s", meta.ID, meta.Version, runtime.Version()[2:], strings.Title(runtime.GOOS)) //nolint:staticcheck // ignoring "SA1019: strings.Title is deprecated", as for our use we don't need full unicode support
if meta.Hostname, err = os.Hostname(); err != nil {
log.Fatal().Err(err).Msg("Cannot resolve hostname")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/journal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func (c *Client) Add(entry Entry) {

// IsEmpty checks if journal is empty
func (c *Client) IsEmpty() bool {
return c.Entries == nil || len(c.Entries) == 0
return len(c.Entries) == 0
}
2 changes: 1 addition & 1 deletion internal/journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func (j Journal) MarshalJSON() ([]byte, error) {

// IsEmpty checks if journal is empty
func (j Journal) IsEmpty() bool {
return j.Entries == nil || len(j.Entries) == 0
return len(j.Entries) == 0
}
2 changes: 1 addition & 1 deletion internal/notif/script/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func (c *Client) Send(jnl journal.Journal) error {
return errors.Wrap(err, strings.TrimSpace(stderr.String()))
}

log.Debug().Msgf(strings.TrimSpace(stdout.String()))
log.Debug().Msg(strings.TrimSpace(stdout.String()))
return nil
}
20 changes: 13 additions & 7 deletions internal/notif/webhook/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"bytes"
"context"
"encoding/json"
"net/http"

Expand Down Expand Up @@ -34,10 +35,6 @@ func (c *Client) Name() string {

// Send creates and sends a webhook notification with journal entries
func (c *Client) Send(jnl journal.Journal) error {
hc := http.Client{
Timeout: *c.cfg.Timeout,
}

body, err := json.Marshal(struct {
Version string `json:"ftpgrab_version,omitempty"`
ServerIP string `json:"server_ip,omitempty"`
Expand All @@ -53,7 +50,11 @@ func (c *Client) Send(jnl journal.Journal) error {
return err
}

req, err := http.NewRequest(c.cfg.Method, c.cfg.Endpoint, bytes.NewBuffer(body))
hc := http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), *c.cfg.Timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, c.cfg.Method, c.cfg.Endpoint, bytes.NewBuffer(body))
if err != nil {
return err
}
Expand All @@ -66,6 +67,11 @@ func (c *Client) Send(jnl journal.Journal) error {

req.Header.Set("User-Agent", c.meta.UserAgent)

_, err = hc.Do(req)
return err
resp, err := hc.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

return nil
}

0 comments on commit 4635752

Please sign in to comment.