diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index af2f881..3eba9d5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,4 +30,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v2 with: - version: v1.33 \ No newline at end of file + version: v1.37.1 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..a5e8daf --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,41 @@ +linters: + enable: + - bodyclose + - cyclop + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - errorlint + - exhaustive + - exportloopref + - forbidigo + - funlen + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - golint + - gomnd + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - lll + - misspell + - nakedret + - rowserrcheck + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace \ No newline at end of file diff --git a/Makefile b/Makefile index 365bce5..3ca0ea1 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,9 @@ clean: $(GOCMD) clean rm -rf $(BINARY) bin/ +lint: + golangci-lint run -v + release: clean compile package docker-build: diff --git a/main.go b/main.go index d5d445b..57b6062 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func mainExec() error { providers := providers.GetProviders() if len(providers) == 0 { - return errors.New("No providers enabled. See configuration.") + return errors.New("no providers enabled. see configuration") } for _, p := range providers { log.Info(fmt.Sprintf("[%v] Provider registered", p.GetName())) diff --git a/news/announcements.go b/news/announcements.go index 06d1747..0f3120b 100644 --- a/news/announcements.go +++ b/news/announcements.go @@ -105,7 +105,7 @@ func Yesterday() (Announcements, error) { // Output: Jan 7, 2020 // parseDate Extracts a standarized date format from the AWS html document. func parseDate(postDate string) string { - r, _ := regexp.Compile(`[A-Z][a-z]{2}\s[0-9]{1,2},\s[0-9]{4}`) + r := regexp.MustCompile(`[A-Z][a-z]{2}\s[0-9]{1,2},\s[0-9]{4}`) // AWS sometimes doesn't have a post date if len(r.FindStringSubmatch(postDate)) > 0 { return r.FindStringSubmatch(postDate)[0] diff --git a/news/examples_test.go b/news/examples_test.go index 238597c..688cc08 100644 --- a/news/examples_test.go +++ b/news/examples_test.go @@ -24,6 +24,7 @@ func ExampleThisMonth() { // Handle error } for _, n := range news { + //nolint fmt.Println(n.Title) } } @@ -33,6 +34,7 @@ func ExampleToday() { if err != nil { // Handle error } + //nolint fmt.Println(news) } @@ -41,6 +43,7 @@ func ExampleYesterday() { if err != nil { // Handle error } + //nolint fmt.Println(news) } @@ -62,6 +65,7 @@ func (a Announcements) ExampleJSON() { if jsonErr != nil { // Handle error } + //nolint fmt.Println(string(json)) } @@ -70,6 +74,7 @@ func (a Announcements) ExampleHTML() { if err != nil { // Handle error } + //nolint fmt.Println(news.Filter([]string{"S3"}).HTML()) } @@ -78,5 +83,6 @@ func (a Announcements) ExampleFilter() { if err != nil { // Handle error } + //nolint fmt.Println(news.Filter([]string{"S3"})) } diff --git a/news/newsdoc.go b/news/newsdoc.go index 2eedb04..1660cb4 100644 --- a/news/newsdoc.go +++ b/news/newsdoc.go @@ -15,8 +15,9 @@ type newsDoc struct { // getNewsDocYear Fetches html from AWS depending on the year/month specified. func getNewsDocYear(year int) (*goquery.Document, error) { + var httpTimeout time.Duration = 10 url := fmt.Sprintf("https://aws.amazon.com/about-aws/whats-new/%d", year) - client := &http.Client{Timeout: 10 * time.Second} + client := &http.Client{Timeout: httpTimeout * time.Second} req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err @@ -36,8 +37,9 @@ func getNewsDocYear(year int) (*goquery.Document, error) { // getNewsDocMonth Fetches html from AWS depending on the year/month specified. func getNewsDocMonth(year int, month int) (*goquery.Document, error) { + var httpTimeout time.Duration = 10 url := fmt.Sprintf("https://aws.amazon.com/about-aws/whats-new/%v/%02d/", year, month) - client := &http.Client{Timeout: 10 * time.Second} + client := &http.Client{Timeout: httpTimeout * time.Second} req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err diff --git a/news/newsdoc_test.go b/news/newsdoc_test.go index d4f48cf..9349fda 100644 --- a/news/newsdoc_test.go +++ b/news/newsdoc_test.go @@ -23,6 +23,7 @@ func init() { defer monthFile.Close() monthDoc, err := goquery.NewDocumentFromReader(monthFile) if err != nil { + //nolint log.Fatal(err) } monthTestDoc = monthDoc @@ -60,15 +61,18 @@ func TestGetSelectionItems(t *testing.T) { func TestGetSelectionTitle(t *testing.T) { news := newsDoc{monthTestDoc} + //nolint assert.Equal(t, news.getSelectionTitle(news.getSelectionItems().First()), "Amazon EKS Announces Beta Release of Amazon FSx for Lustre CSI Driver") } func TestGetSelectionLink(t *testing.T) { news := newsDoc{monthTestDoc} + //nolint assert.Equal(t, news.getSelectionItemLink(news.getSelectionItems().First()), "https://aws.amazon.com/about-aws/whats-new/2019/12/amazon-eks-announces-beta-release-amazon-fsx-lustre-csi-driver/") } func TestGetSelectionDate(t *testing.T) { news := newsDoc{monthTestDoc} + //nolint assert.Equal(t, news.getSelectionItemDate(news.getSelectionItems().First()), "\n Posted On: Dec 23, 2019 \n ") } diff --git a/providers/discord/discord.go b/providers/discord/discord.go index fe49f52..a7aa536 100644 --- a/providers/discord/discord.go +++ b/providers/discord/discord.go @@ -101,13 +101,13 @@ func (p *Provider) post(embeds []Embed) error { json, err := json.Marshal(payload) if err != nil { - return fmt.Errorf("[%s] %v", p.GetName(), err) + return fmt.Errorf("[%s] %w", p.GetName(), err) } log.Info(fmt.Sprintf("[%v] Firing notification", p.GetName())) res, err := http.Post(p.WebhookURL, "application/json", bytes.NewBuffer(json)) if err != nil { - return fmt.Errorf("[%v] %v", p.GetName(), err) + return fmt.Errorf("[%v] %w", p.GetName(), err) } defer res.Body.Close() diff --git a/providers/rocketchat/rocketchat.go b/providers/rocketchat/rocketchat.go index 1512a96..88fef72 100644 --- a/providers/rocketchat/rocketchat.go +++ b/providers/rocketchat/rocketchat.go @@ -56,7 +56,6 @@ func (*Provider) GetName() string { // Notify is the function executed to POST to a provider's webhook url. func (p *Provider) Notify(news news.Announcements) { - var b strings.Builder for _, v := range news { b.WriteString(fmt.Sprintf("[%s](%s) - %s\n", v.Title, v.Link, v.PostDate)) diff --git a/providers/slack/slack.go b/providers/slack/slack.go index e159bbd..27b0fc1 100644 --- a/providers/slack/slack.go +++ b/providers/slack/slack.go @@ -56,7 +56,6 @@ func (*Provider) GetName() string { // Notify is the function executed to POST to a provider's webhook url. func (p *Provider) Notify(news news.Announcements) { - var b strings.Builder for _, v := range news { b.WriteString(fmt.Sprintf("<%s|%s> - %s\n", v.Link, v.Title, v.PostDate)) diff --git a/providers/smtp/smtp.go b/providers/smtp/smtp.go index 6f48982..8fb2d70 100644 --- a/providers/smtp/smtp.go +++ b/providers/smtp/smtp.go @@ -66,7 +66,6 @@ func (*Provider) GetName() string { // Notify is the function executed to POST to a provider's webhook url. func (p *Provider) Notify(news news.Announcements) { - m := &email{ addr: fmt.Sprintf("%s:%s", p.Server, p.Port), from: p.From,