Skip to content

Commit 2f09ae0

Browse files
authored
Merge pull request #21 from nginxinc/add-lint
Add lint option to Makefile and fix lint issues
2 parents f8affc0 + e8d9977 commit 2f09ae0

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ Note: if you’d like to implement a new feature, please consider creating a fea
6767
* Run `gofmt` over your code to automatically resolve a lot of style issues. Most editors support this running automatically when saving a code file.
6868
* Run `go lint` and `go vet` on your code too to catch any other issues.
6969
* Follow this guide on some good practice and idioms for Go - https://github.com/golang/go/wiki/CodeReviewComments
70+
* To check for extra issues, install [golangci-lint](https://github.com/golangci/golangci-lint) and run `make lint` or `golangci-lint run`

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ else
1111
go test ./...
1212
endif
1313

14+
lint:
15+
golangci-lint run
16+
1417
compile: test
1518
ifeq ($(BUILD_IN_CONTAINER),1)
1619
$(GO_DOCKER_RUN) $(GOLANG_CONTAINER) go build -o /build_output/nginx-asg-sync

cmd/sync/aws.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ func (client *AWSClient) getInstancesOfAutoscalingGroup(group *autoscaling.Group
9191
return result, err
9292
}
9393
for _, res := range resp.Reservations {
94-
for _, ins := range res.Instances {
95-
result = append(result, ins)
96-
}
94+
result = append(result, res.Instances...)
9795
}
9896

9997
return result, nil

cmd/sync/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func main() {
5858
os.Exit(10)
5959
}
6060

61-
awsClient := createAWSClient(cfg.Region)
61+
awsClient, err := createAWSClient(cfg.Region)
62+
if err != nil {
63+
log.Printf("Couldn't create AWS client: %v", err)
64+
os.Exit(10)
65+
}
6266

6367
for _, ups := range cfg.Upstreams {
6468
if ups.Kind == "http" {
@@ -142,11 +146,16 @@ func main() {
142146
}
143147
}
144148

145-
func createAWSClient(region string) *AWSClient {
149+
func createAWSClient(region string) (*AWSClient, error) {
146150
httpClient := &http.Client{Timeout: connTimeoutInSecs * time.Second}
147151
cfg := &aws.Config{Region: aws.String(region), HTTPClient: httpClient}
148-
session := session.New(cfg)
152+
153+
session, err := session.NewSession(cfg)
154+
if err != nil {
155+
return nil, err
156+
}
157+
149158
svcAutoscaling := autoscaling.New(session)
150159
svcEC2 := ec2.New(session)
151-
return NewAWSClient(svcEC2, svcAutoscaling)
160+
return NewAWSClient(svcEC2, svcAutoscaling), nil
152161
}

0 commit comments

Comments
 (0)