Skip to content

Commit da8221c

Browse files
committed
use golangci-lint, improve code quality
1 parent 8bf2f28 commit da8221c

File tree

7 files changed

+47
-13
lines changed

7 files changed

+47
-13
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ env:
99
services:
1010
- docker
1111

12+
before_install:
13+
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.32.2
14+
1215
script:
13-
- go vet ./...
14-
- make test
16+
- make test
1517

1618
after_success:
1719
- bash <(curl -s https://codecov.io/bash) -t "${CODECOV_TOKEN}" -f coverage.txt -Z

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ GOCMD=go
22
BINARY=awsnews
33
BUILD_FLAGS=-ldflags="-s -w"
44
PROJECT=circa10a/go-aws-news
5-
VERSION=1.0.0
5+
VERSION=1.1.0
66

77
# First target for travis ci
88
test:
99
$(GOCMD) test -v ./... -coverprofile=coverage.txt
10+
@if ! command -v golangci-lint 1>/dev/null; then\
11+
echo "Need to install golangci-lint";\
12+
exit 1;\
13+
fi;\
14+
golangci-lint run
1015

1116
coverage:
1217
$(GOCMD) test -coverprofile=coverage.txt ./... && go tool cover -html=coverage.txt

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/olekukonko/tablewriter v0.0.4
1010
github.com/sirupsen/logrus v1.7.0
1111
github.com/stretchr/testify v1.6.1
12-
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 // indirect
13-
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7 // indirect
12+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 // indirect
13+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf // indirect
1414
gopkg.in/yaml.v2 v2.3.0
1515
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73r
2929
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3030
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
3131
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
32-
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg=
33-
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
32+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
33+
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
3434
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3535
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3636
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
3737
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3838
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
39-
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7 h1:XtNJkfEjb4zR3q20BBBcYUykVOEMgZeIUOpBPfNYgxg=
40-
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
39+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf h1:kt3wY1Lu5MJAnKTfoMR52Cu4gwvna4VTzNOiT8tY73s=
40+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4141
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4242
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
4343
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

news/announcements.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func Yesterday() (Announcements, error) {
105105
// Output: Jan 7, 2020
106106
// parseDate Extracts a standarized date format from the AWS html document.
107107
func parseDate(postDate string) string {
108-
r, _ := regexp.Compile("[A-Z][a-z]{2}\\s[0-9]{1,2},\\s[0-9]{4}")
108+
r, _ := regexp.Compile(`[A-Z][a-z]{2}\s[0-9]{1,2},\s[0-9]{4}`)
109109
// AWS sometimes doesn't have a post date
110110
if len(r.FindStringSubmatch(postDate)) > 0 {
111111
return r.FindStringSubmatch(postDate)[0]

news/newsdoc.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package news
22

33
import (
44
"fmt"
5+
"net/http"
6+
"time"
57

68
"github.com/PuerkitoBio/goquery"
79
)
@@ -14,7 +16,18 @@ type newsDoc struct {
1416
// getNewsDocYear Fetches html from AWS depending on the year/month specified.
1517
func getNewsDocYear(year int) (*goquery.Document, error) {
1618
url := fmt.Sprintf("https://aws.amazon.com/about-aws/whats-new/%d", year)
17-
doc, err := goquery.NewDocument(url)
19+
client := &http.Client{Timeout: 10 * time.Second}
20+
req, err := http.NewRequest("GET", url, nil)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
r, err := client.Do(req)
26+
if err != nil {
27+
return nil, err
28+
}
29+
defer r.Body.Close()
30+
doc, err := goquery.NewDocumentFromReader(r.Body)
1831
if err != nil {
1932
return doc, err
2033
}
@@ -24,7 +37,18 @@ func getNewsDocYear(year int) (*goquery.Document, error) {
2437
// getNewsDocMonth Fetches html from AWS depending on the year/month specified.
2538
func getNewsDocMonth(year int, month int) (*goquery.Document, error) {
2639
url := fmt.Sprintf("https://aws.amazon.com/about-aws/whats-new/%v/%02d/", year, month)
27-
doc, err := goquery.NewDocument(url)
40+
client := &http.Client{Timeout: 10 * time.Second}
41+
req, err := http.NewRequest("GET", url, nil)
42+
if err != nil {
43+
return nil, err
44+
}
45+
46+
r, err := client.Do(req)
47+
if err != nil {
48+
return nil, err
49+
}
50+
defer r.Body.Close()
51+
doc, err := goquery.NewDocumentFromReader(r.Body)
2852
if err != nil {
2953
return doc, err
3054
}

providers/smtp/smtp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ func (p *Provider) Notify(news news.Announcements) {
8484
auth = smtp.PlainAuth("", p.Username, p.Password, p.Server)
8585
}
8686

87-
m.parseTemplate()
87+
err := m.parseTemplate()
88+
if err != nil {
89+
log.Error(fmt.Sprintf("[%v] %v", p.GetName(), err))
90+
}
8891

8992
log.Info(fmt.Sprintf("[%v] Firing notification", p.GetName()))
9093
if err := m.sendMail(auth); err != nil {

0 commit comments

Comments
 (0)