Skip to content

Commit f2dc67f

Browse files
committed
fix some lints
1 parent 6625a4a commit f2dc67f

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var keyName string
1212
var tableName string
1313
var regionName string
1414

15-
// rootCmd represents the base command when called without any subcommands
15+
// rootCmd represents the base command when called without any subcommands.
1616
var rootCmd = &cobra.Command{
1717
Use: "lock-exec",
1818
Short: "A CLI tool for running any shell based commands in a distributed environment with DynamoDB locking",

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var shellCommand string
1010
var sleepStartRandom int
1111
var holdLockBy int
1212

13-
// runCmd represents the run command
13+
// runCmd represents the run command.
1414
var runCmd = &cobra.Command{
1515
Use: "run",
1616
Short: "Run a shell command with acquire lock",

cmd/unlock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
// unlockCmd represents the unlock command
9+
// unlockCmd represents the unlock command.
1010
var unlockCmd = &cobra.Command{
1111
Use: "unlock",
1212
Short: "Force release an already acquired lock using key name",

cmd/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
)
88

99
var (
10-
// Version is defined at compile time via -ldflags
10+
// Version is defined at compile time via -ldflags.
1111
Version = "undefined1"
1212
)
1313

14-
// unlockCmd represents the unlock command
14+
// unlockCmd represents the unlock command.
1515
var versionkCmd = &cobra.Command{
1616
Use: "version",
1717
Short: "Print version",

exec/exec.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ const (
2424

2525
var execCommand = exec.Command
2626

27-
// Exec is a struct used to work with dynamo client interface
27+
// Exec is a struct used to work with dynamo client interface.
2828
type Exec struct {
2929
dynamodbiface.DynamoDBAPI
3030
}
3131

32-
// NewDynamoClient returns a Dynamo struct with client
33-
// session
32+
// NewDynamoClient returns a Dynamo struct with client session.
3433
func NewDynamoClient(awsRegionName string) (*Exec, error) {
3534
sess := utils.AWSSession(awsRegionName)
3635
dynamoClient := dynamodb.New(sess)
@@ -45,7 +44,7 @@ func NewDynamoClient(awsRegionName string) (*Exec, error) {
4544
// If sleepStartRandom & holdLockBy have non-zero values, it accordingly
4645
// introduces randomized sleep before start and holds the lock by that duration
4746
// before stop.
48-
func (d *Exec) Run(tableName string, keyName string, command string, sleepStartRandom int, holdLockBy int) error {
47+
func (d *Exec) Run(tableName string, keyName string, command string, sleepStartRandom int, holdLockBy int) error { //nolint:funlen
4948
if sleepStartRandom > 0 {
5049
randomizeSleep(sleepStartRandom)
5150
}
@@ -74,6 +73,7 @@ func (d *Exec) Run(tableName string, keyName string, command string, sleepStartR
7473

7574
// Exit early, just not as an error.
7675
logrus.Warning(err)
76+
7777
return nil
7878
}
7979
logrus.Info("Lock acquired")
@@ -117,7 +117,7 @@ func (d *Exec) Run(tableName string, keyName string, command string, sleepStartR
117117
}
118118

119119
// RunCommand executes the command.
120-
// It returns the output into STDOUT
120+
// It returns the output into STDOUT.
121121
func runExec(command string) (string, error) {
122122
args := strings.Fields(command)
123123

@@ -126,8 +126,8 @@ func runExec(command string) (string, error) {
126126
stdoutStderr, err := cmd.CombinedOutput()
127127
if err != nil {
128128
return string(stdoutStderr), err
129-
130129
}
130+
131131
return string(stdoutStderr), nil
132132
}
133133

@@ -137,14 +137,14 @@ func randomizeSleep(i int) {
137137
rand.Seed(time.Now().UnixNano())
138138
ms := i * 1000
139139
offsetMS := 100 // milliseconds
140-
r := minRandomSleep + rand.Intn(ms-minRandomSleep+offsetMS) // ensures that the random range is [1, i]. To avoid sleeping for 0 seconds (0 ms).
140+
r := minRandomSleep + rand.Intn(ms-minRandomSleep+offsetMS) //nolint:gosec // ensures that the random range is [1, i]. To avoid sleeping for 0 seconds (0 ms).
141141

142142
logrus.Infof("Randomized execution. Sleeping for %d milliseconds.", r)
143143

144144
time.Sleep(time.Duration(r) * time.Millisecond)
145145
}
146146

147-
// sleepBy takes a int input, and sleeps for that duration
147+
// sleepBy takes a int input, and sleeps for that duration.
148148
func sleepBy(i int) {
149149
logrus.Infof("Holding lock - Sleeping for %d seconds.", i)
150150

lock/lock.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import (
88
"github.com/sirupsen/logrus"
99
)
1010

11-
// Dynamo is a struct used to work with dynamo client interface
11+
// Dynamo is a struct used to work with dynamo client interface.
1212
type Dynamo struct {
1313
dynamodbiface.DynamoDBAPI
1414
}
1515

16-
// NewDynamoClient returns a Dynamo struct with client
17-
// session
16+
// NewDynamoClient returns a Dynamo struct with client session.
1817
func NewDynamoClient(awsRegionName string) *Dynamo {
1918
sess := utils.AWSSession(awsRegionName)
2019

@@ -35,14 +34,14 @@ func (d *Dynamo) ReleaseLock(keyName string, tableName string) error {
3534
TableName: aws.String(tableName),
3635
}
3736

38-
_, err := d.DeleteItem(input)
39-
if err != nil {
37+
if _, err := d.DeleteItem(input); err != nil {
4038
return err
4139
}
4240

4341
logrus.WithFields(logrus.Fields{
4442
"key": keyName,
4543
"table": tableName,
4644
}).Info("Releasing lock")
45+
4746
return nil
4847
}

utils/aws.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
)
77

88
const (
9-
// Region is default AWS region when none provided
9+
// Region is default AWS region when none provided.
1010
Region = "us-west-2"
1111

12-
// TableName is the default table name when none provided
12+
// TableName is the default table name when none provided.
1313
TableName = "lock-exec"
1414
)
1515

16-
// AWSSession generates an aws api session in us-west-2
16+
// AWSSession generates an aws api session in us-west-2.
1717
func AWSSession(region string) *session.Session {
1818
return session.Must(session.NewSessionWithOptions(session.Options{
1919
Config: aws.Config{

0 commit comments

Comments
 (0)