diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57c7a78..9de88d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,9 +23,10 @@ jobs: - run: make format - - uses: grandcolline/golang-github-actions@v1.1.0 + - uses: actions-contrib/golangci-lint@v1 + env: + GOROOT: "" with: - run: lint - token: ${{ secrets.GITHUB_TOKEN }} + args: "run" - run: make build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 641e016..1a8279b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -31,10 +31,11 @@ jobs: - run: make format - - uses: grandcolline/golang-github-actions@v1.1.0 + - uses: actions-contrib/golangci-lint@v1 + env: + GOROOT: "" with: - run: lint - token: ${{ secrets.GITHUB_TOKEN }} + args: "run" - run: make build diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..34a42cd --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +run: + skip-dirs: + - node_modules diff --git a/Makefile b/Makefile index 17e8b43..fb7c943 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ format: test -z $$(gofmt -l .) lint: - golint -set_exit_status ./... + golangci-lint run build: @for function in $(functions) ; do \ diff --git a/functions/handle_tweet/main_test.go b/functions/handle_tweet/main_test.go index 896926c..e8fd570 100644 --- a/functions/handle_tweet/main_test.go +++ b/functions/handle_tweet/main_test.go @@ -26,7 +26,7 @@ func TestHandleTweetExits(t *testing.T) { dbMock.ExpectQuery("SELECT (.+) FROM (.+) WHERE (.+) LIMIT 1"). WithArgs(bill.TweetID). WillReturnRows(sqlmock.NewRows([]string{"pk", "tweet_id"}).AddRow(1, 1234)) - handleTweet(&bill, DB, snsMock) + _ = handleTweet(&bill, DB, snsMock) if err := dbMock.ExpectationsWereMet(); err != nil { t.Errorf("there were unfulfilled expectations: %s", err) } @@ -48,7 +48,7 @@ func TestHandleTweetEmptyBillID(t *testing.T) { WithArgs(bill.TweetID). WillReturnError(gorm.ErrRecordNotFound) snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - handleTweet(&bill, DB, snsMock) + _ = handleTweet(&bill, DB, snsMock) if err := dbMock.ExpectationsWereMet(); err != nil { t.Errorf("there were unfulfilled expectations: %s", err) } diff --git a/functions/query_mentions/main_test.go b/functions/query_mentions/main_test.go index a3168ca..3ca8236 100644 --- a/functions/query_mentions/main_test.go +++ b/functions/query_mentions/main_test.go @@ -12,7 +12,7 @@ import ( func TestQueryMentionsIgnoresEmptyBillID(t *testing.T) { tweets := []twitter.Tweet{ - twitter.Tweet{ + { ID: 1, Text: "Testing bill", User: &twitter.User{ScreenName: "testuser"}, @@ -23,13 +23,13 @@ func TestQueryMentionsIgnoresEmptyBillID(t *testing.T) { snsMock := new(mocks.SNSClientMock) twttrMock.On("GetMentions", mock.Anything).Return(tweets, nil) snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - queryMentions(twttrMock, snsMock) + _ = queryMentions(twttrMock, snsMock) snsMock.AssertNotCalled(t, "Publish", mock.Anything, mock.Anything, "handle_tweet") } func TestQueryMentionsIgnoresOldTweet(t *testing.T) { tweets := []twitter.Tweet{ - twitter.Tweet{ + { ID: 1, Text: "@chicagoledger O2010-11 Testing bill", User: &twitter.User{ScreenName: "testuser"}, @@ -40,14 +40,14 @@ func TestQueryMentionsIgnoresOldTweet(t *testing.T) { snsMock := new(mocks.SNSClientMock) twttrMock.On("GetMentions", mock.Anything).Return(tweets, nil) snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - queryMentions(twttrMock, snsMock) + _ = queryMentions(twttrMock, snsMock) snsMock.AssertNotCalled(t, "Publish", mock.Anything, mock.Anything, "handle_tweet") } func TestQueryMentionsTweetsBill(t *testing.T) { - log.Printf(time.Now().UTC().String()) + log.Println(time.Now().UTC().String()) tweets := []twitter.Tweet{ - twitter.Tweet{ + { ID: 1, Text: "@chicagoledger O2010-11 Testing bill", User: &twitter.User{ScreenName: "testuser"}, @@ -58,6 +58,6 @@ func TestQueryMentionsTweetsBill(t *testing.T) { snsMock := new(mocks.SNSClientMock) twttrMock.On("GetMentions", mock.Anything).Return(tweets, nil) snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - queryMentions(twttrMock, snsMock) + _ = queryMentions(twttrMock, snsMock) snsMock.AssertCalled(t, "Publish", mock.Anything, mock.Anything, "handle_tweet") } diff --git a/functions/update_bill/main.go b/functions/update_bill/main.go index 5ea6b17..828de2f 100644 --- a/functions/update_bill/main.go +++ b/functions/update_bill/main.go @@ -54,7 +54,7 @@ func handler(request events.SNSEvent) error { err := json.Unmarshal([]byte(message), &bill) // Log errors because we don't want to trigger Lambda's retries if err != nil { - snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill") + _ = snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill") log.Println(err) return nil } @@ -70,7 +70,7 @@ func handler(request events.SNSEvent) error { err = updateBill(bill, actions, snsClient) // Only log this error since it just prevented if err != nil { - snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill") + _ = snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill") log.Println(err) } return nil diff --git a/functions/update_bill/main_test.go b/functions/update_bill/main_test.go index 8cab2bb..8e35834 100644 --- a/functions/update_bill/main_test.go +++ b/functions/update_bill/main_test.go @@ -18,7 +18,7 @@ func TestUpdateBillIgnoresNoChanges(t *testing.T) { Data: `[]`, } snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - updateBill(bill, []models.LegistarAction{}, snsMock) + _ = updateBill(bill, []models.LegistarAction{}, snsMock) snsMock.AssertCalled(t, "Publish", mock.Anything, mock.Anything, "save_bill") } @@ -29,7 +29,7 @@ func TestUpdateBillNilNextRunSendsTweet(t *testing.T) { Data: `[]`, } snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - updateBill(bill, []models.LegistarAction{}, snsMock) + _ = updateBill(bill, []models.LegistarAction{}, snsMock) snsMock.AssertExpectations(t) snsMock.AssertNumberOfCalls(t, "Publish", 2) } @@ -44,10 +44,10 @@ func TestUpdateBillNewActionsSendsTweet(t *testing.T) { } actionDate, _ := time.Parse("2006-01-02", "2019-01-01") actions := []models.LegistarAction{ - models.LegistarAction{Date: actionDate, Action: "introduction", Actor: "Test"}, + {Date: actionDate, Action: "introduction", Actor: "Test"}, } snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil) - updateBill(bill, actions, snsMock) + _ = updateBill(bill, actions, snsMock) snsMock.AssertExpectations(t) snsMock.AssertNumberOfCalls(t, "Publish", 2) } diff --git a/go.mod b/go.mod index 20261c8..f1558d6 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,9 @@ require ( github.com/dghubble/go-twitter v0.0.0-20190512073027-53f972dc4b06 github.com/dghubble/oauth1 v0.5.0 github.com/dghubble/sling v1.2.0 // indirect + github.com/fnproject/fdk-go v0.0.3 github.com/google/go-querystring v1.0.0 // indirect github.com/jinzhu/gorm v1.9.8 github.com/stretchr/testify v1.2.2 + github.com/tencentyun/scf-go-lib v0.0.0-20200624065115-ba679e2ec9c9 ) diff --git a/go.sum b/go.sum index 61b141a..6716e17 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= +github.com/fnproject/fdk-go v0.0.3 h1:CkUsIH0QmWDb/vDU3lGoP+Fl0VIfk2/xi1v82Qk5vCs= +github.com/fnproject/fdk-go v0.0.3/go.mod h1:9m+nEyku9SqJAVJQsfZOZBQzFkCs+jvmbZJhvgDX4ts= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -102,6 +104,8 @@ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/tencentyun/scf-go-lib v0.0.0-20200624065115-ba679e2ec9c9 h1:JdeXp/XPi7lBmpQNSUxElMAvwppMlFSiamTtXYRFuUc= +github.com/tencentyun/scf-go-lib v0.0.0-20200624065115-ba679e2ec9c9/go.mod h1:K3DbqPpP2WE/9MWokWWzgFZcbgtMb9Wd5CYk9AAbEN8= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/pkg/svc/sns.go b/pkg/svc/sns.go index 1a204f8..f449817 100644 --- a/pkg/svc/sns.go +++ b/pkg/svc/sns.go @@ -18,7 +18,8 @@ type SNSClient struct { // NewSNSClient creates an SNSClient object func NewSNSClient() *SNSClient { - client := sns.New(session.New()) + sess, _ := session.NewSession() + client := sns.New(sess) return &SNSClient{Client: client} } @@ -28,7 +29,7 @@ func (c *SNSClient) Publish(message string, topicArn string, feed string) error Message: aws.String(message), TopicArn: aws.String(topicArn), MessageAttributes: map[string]*sns.MessageAttributeValue{ - "feed": &sns.MessageAttributeValue{ + "feed": { DataType: aws.String("String"), StringValue: aws.String(feed), }, diff --git a/pkg/svc/twitter.go b/pkg/svc/twitter.go index 2fec36b..8980a44 100644 --- a/pkg/svc/twitter.go +++ b/pkg/svc/twitter.go @@ -41,7 +41,7 @@ func NewTwitterClient() *TwitterClient { // PostTweet posts a tweet to Twitter func (t *TwitterClient) PostTweet(tweet string, params *twitter.StatusUpdateParams) error { - log.Printf(tweet) + log.Println(tweet) _, _, err := t.Client.Statuses.Update(tweet, params) return err }