Skip to content

Commit

Permalink
Merge pull request #4 from dmitris/staticcheck
Browse files Browse the repository at this point in the history
correct staticcheck issues
  • Loading branch information
mehrdadrad committed Jun 22, 2020
2 parents 6aab376 + efc5a57 commit 8d9c92f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
16 changes: 4 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,7 @@ func (c *clientAttr) newSession() (*ssh.Session, error) {
}

func (c *clientAttr) isSessionsMaxOut() bool {
if c.getSessions() >= c.maxSessions {
return true
}

return false
return c.getSessions() >= c.maxSessions
}

func (c *clientAttr) getScanners(s *ssh.Session, lOut, lErr int64) (*bufio.Scanner, *bufio.Scanner, error) {
Expand Down Expand Up @@ -488,7 +484,7 @@ func (r *Response) ExitStatus() int {
}

// ScanStdout provides a convenient interface for reading stdout
// which it connected to remote host. it reads a line and buffer
// which it connected to remote host. It reads a line and buffers
// it. the TextStdout() or BytesStdout() methods returns the buffer
// in string or bytes.
func (s *Stream) ScanStdout() bool {
Expand All @@ -498,9 +494,7 @@ func (s *Stream) ScanStdout() bool {

var ok bool

select {
case s.stdout, ok = <-s.r.outChan:
}
s.stdout, ok = <-s.r.outChan

return ok
}
Expand All @@ -526,9 +520,7 @@ func (s *Stream) ScanStderr() bool {

var ok bool

select {
case s.stderr, ok = <-s.r.errChan:
}
s.stderr, ok = <-s.r.errChan

return ok
}
Expand Down
3 changes: 1 addition & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ func TestNewSession(t *testing.T) {

// enable pty - test server doesn't support
client.pty.enabled = true
session, err = client.newSession()
if err == nil {
if _, err = client.newSession(); err == nil {
t.Fatal("expect error but got", err)
}
}
Expand Down
9 changes: 7 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func Example_cloud() {
Region: aws.String("us-west-1"),
Credentials: credentials.NewStaticCredentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", ""),
}
ec2svc := ec2.New(session.New(awsConfig))
sess, err := session.NewSession(awsConfig)
if err != nil {
fmt.Println("error creating new session:", err.Error())
log.Fatal(err)
}
ec2svc := ec2.New(sess)
params := &ec2.DescribeInstancesInput{
// filter running instances at us-west-1
Filters: []*ec2.Filter{
Expand All @@ -136,7 +141,7 @@ func Example_cloud() {
for idx := range resp.Reservations {
for _, inst := range resp.Reservations[idx].Instances {
labels := make(map[string]string)
for _, tag := range *&inst.Tags {
for _, tag := range inst.Tags {
labels[*tag.Key] = *tag.Value
}
addr := net.JoinHostPort(*inst.PublicIpAddress, "22")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module github.com/yahoo/vssh
go 1.14

require (
github.com/aws/aws-sdk-go v1.32.6
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
github.com/aws/aws-sdk-go v1.32.6 h1:HoswAabUWgnrUF7X/9dr4WRgrr8DyscxXvTDm7Qw/5c=
github.com/aws/aws-sdk-go v1.32.6/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
8 changes: 3 additions & 5 deletions vssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type VSSH struct {
logger *log.Logger
stats stats
mode bool
ctx context.Context
bufPool sync.Pool

actionQ chan task
Expand All @@ -57,9 +56,7 @@ type VSSH struct {
}

type stats struct {
errors uint64
queries uint64
clients uint64
connects uint64
processes uint64
}
Expand Down Expand Up @@ -363,10 +360,11 @@ func (v *VSSH) reConnect(ctx context.Context) {
if v.mode {
return
}

ticker := time.NewTicker(reConnDur)
defer ticker.Stop()
for {
select {
case <-time.Tick(reConnDur):
case <-ticker.C:
for client := range v.clients.enum() {
if client.err != nil && client.stats.errRecent < maxErrRecent {
if client.client != nil {
Expand Down

0 comments on commit 8d9c92f

Please sign in to comment.