@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "net/http"
78 "reflect"
@@ -34,18 +35,18 @@ func NewAWSClient(data []byte) (*AWSClient, error) {
3435 if cfg .Region == "self" {
3536 httpClient := & http.Client {Timeout : connTimeoutInSecs * time .Second }
3637
37- conf , err := config .LoadDefaultConfig (context .TODO ())
38- if err != nil {
39- return nil , err
38+ conf , loadErr := config .LoadDefaultConfig (context .TODO ())
39+ if loadErr != nil {
40+ return nil , loadErr
4041 }
4142
4243 client := imds .NewFromConfig (conf , func (o * imds.Options ) {
4344 o .HTTPClient = httpClient
4445 })
4546
46- response , err := client .GetRegion (context .TODO (), & imds.GetRegionInput {})
47- if err != nil {
48- return nil , fmt .Errorf ("unable to retrieve region from ec2metadata: %w" , err )
47+ response , regionErr := client .GetRegion (context .TODO (), & imds.GetRegionInput {})
48+ if regionErr != nil {
49+ return nil , fmt .Errorf ("unable to retrieve region from ec2metadata: %w" , regionErr )
4950 }
5051 cfg .Region = response .Region
5152 }
@@ -197,13 +198,13 @@ func (client *AWSClient) getInstancesInService(insIDtoIP map[string]string) ([]s
197198 const maxItems = 50
198199 var result []string
199200 keys := reflect .ValueOf (insIDtoIP ).MapKeys ()
200- instanceIds := make ([]string , len (keys ))
201+ instanceIDs := make ([]string , len (keys ))
201202
202203 for i := 0 ; i < len (keys ); i ++ {
203- instanceIds [i ] = keys [i ].String ()
204+ instanceIDs [i ] = keys [i ].String ()
204205 }
205206
206- batches := prepareBatches (maxItems , instanceIds )
207+ batches := prepareBatches (maxItems , instanceIDs )
207208 for _ , batch := range batches {
208209 params := & autoscaling.DescribeAutoScalingInstancesInput {
209210 InstanceIds : batch ,
@@ -249,13 +250,13 @@ type awsConfig struct {
249250type awsUpstream struct {
250251 Name string
251252 AutoscalingGroup string `yaml:"autoscaling_group"`
252- Port int
253253 Kind string
254- MaxConns int `yaml:"max_conns"`
255- MaxFails int `yaml:"max_fails"`
256254 FailTimeout string `yaml:"fail_timeout"`
257255 SlowStart string `yaml:"slow_start"`
258- InService bool `yaml:"in_service"`
256+ Port int
257+ MaxConns int `yaml:"max_conns"`
258+ MaxFails int `yaml:"max_fails"`
259+ InService bool `yaml:"in_service"`
259260}
260261
261262func validateAWSConfig (cfg * awsConfig ) error {
@@ -264,12 +265,12 @@ func validateAWSConfig(cfg *awsConfig) error {
264265 }
265266
266267 if len (cfg .Upstreams ) == 0 {
267- return fmt . Errorf ("there are no upstreams found in the config file" )
268+ return errors . New ("there are no upstreams found in the config file" )
268269 }
269270
270271 for _ , ups := range cfg .Upstreams {
271272 if ups .Name == "" {
272- return fmt . Errorf (upstreamNameErrorMsg )
273+ return errors . New (upstreamNameErrorMsg )
273274 }
274275 if ups .AutoscalingGroup == "" {
275276 return fmt .Errorf (upstreamErrorMsgFormat , "autoscaling_group" , ups .Name )
0 commit comments