From 19760be0bc5b809f7651075fb2c08e32466d69e4 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 21 Dec 2016 03:10:25 -0500 Subject: [PATCH] golint: Fix some golint issues --- etcd/etcd.go | 2 +- examples/lib/libmgmt3.go | 2 +- pgraph/pgraph.go | 1 + puppet/puppet.go | 3 ++- remote/remote.go | 32 ++++++++++++++++---------------- yamlgraph/gconfig.go | 7 ------- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/etcd/etcd.go b/etcd/etcd.go index 51d4841e..b6cde999 100644 --- a/etcd/etcd.go +++ b/etcd/etcd.go @@ -316,7 +316,7 @@ func (obj *EmbdEtcd) Connect(reconnect bool) error { if emax > maxClientConnectRetries { log.Printf("Etcd: The dataDir (%s) might be inconsistent or corrupt.", obj.dataDir) log.Printf("Etcd: Please see: %s", "https://github.com/purpleidea/mgmt/blob/master/DOCUMENTATION.md#what-does-the-error-message-about-an-inconsistent-datadir-mean") - obj.cError = fmt.Errorf("Can't find an available endpoint.") + obj.cError = fmt.Errorf("can't find an available endpoint") return obj.cError } err = &CtxDelayErr{time.Duration(emax) * time.Second, "No endpoints available yet!"} // retry with backoff... diff --git a/examples/lib/libmgmt3.go b/examples/lib/libmgmt3.go index 3c334b58..830d1f36 100644 --- a/examples/lib/libmgmt3.go +++ b/examples/lib/libmgmt3.go @@ -86,7 +86,7 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) { Name: "file1", // send->recv! Recv: map[string]*resources.Send{ - "Content": &resources.Send{Res: p1, Key: "Password"}, + "Content": {Res: p1, Key: "Password"}, }, }, Path: "/tmp/mgmt/secret", diff --git a/pgraph/pgraph.go b/pgraph/pgraph.go index d698f139..826321c7 100644 --- a/pgraph/pgraph.go +++ b/pgraph/pgraph.go @@ -40,6 +40,7 @@ const ( graphStatePaused ) +// Flags contains specific constants used by the graph. type Flags struct { Debug bool } diff --git a/puppet/puppet.go b/puppet/puppet.go index 11a82665..c8f23bc7 100644 --- a/puppet/puppet.go +++ b/puppet/puppet.go @@ -32,7 +32,8 @@ import ( const ( // PuppetYAMLBufferSize is the maximum buffer size for the yaml input data PuppetYAMLBufferSize = 65535 - Debug = false // FIXME: integrate with global debug flag + // Debug is a local debug constant used in this module + Debug = false // FIXME: integrate with global debug flag ) func runPuppetCommand(cmd *exec.Cmd) ([]byte, error) { diff --git a/remote/remote.go b/remote/remote.go index 12477e7e..24d926b3 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -156,11 +156,11 @@ func (obj *SSH) Sftp() error { var err error if obj.client == nil { - return fmt.Errorf("Not dialed!") + return fmt.Errorf("not dialed") } // this check is needed because the golang path.Base function is weird! if strings.HasSuffix(obj.file, "/") { - return fmt.Errorf("File must not be a directory.") + return fmt.Errorf("file must not be a directory") } // we run local operations first so that remote clean up is easier... @@ -254,7 +254,7 @@ func (obj *SSH) Sftp() error { // make file executable; don't cache this in case it didn't ever happen // TODO: do we want the group or other bits set? if err := obj.sftp.Chmod(obj.execpath, 0770); err != nil { - return fmt.Errorf("Can't set file mode bits!") + return fmt.Errorf("can't set file mode bits") } // copy graph file @@ -273,7 +273,7 @@ func (obj *SSH) Sftp() error { // SftpGraphCopy is a helper function used for re-copying the graph definition. func (obj *SSH) SftpGraphCopy() (int64, error) { if obj.filepath == "" { - return -1, fmt.Errorf("Sftp session isn't ready yet!") + return -1, fmt.Errorf("sftp session isn't ready yet") } return obj.SftpCopy(obj.file, obj.filepath) } @@ -281,7 +281,7 @@ func (obj *SSH) SftpGraphCopy() (int64, error) { // SftpCopy is a simple helper function that runs a local -> remote sftp copy. func (obj *SSH) SftpCopy(src, dst string) (int64, error) { if obj.sftp == nil { - return -1, fmt.Errorf("Sftp session is not active!") + return -1, fmt.Errorf("sftp session is not active") } var err error // TODO: add a check to make sure we don't run two copies of this @@ -313,7 +313,7 @@ func (obj *SSH) SftpCopy(src, dst string) (int64, error) { return n, fmt.Errorf("Can't copy to remote path: %v", err) } if n <= 0 { - return n, fmt.Errorf("Zero bytes copied!") + return n, fmt.Errorf("zero bytes copied") } return n, nil } @@ -391,10 +391,10 @@ func (obj *SSH) Tunnel() error { var err error if len(obj.clientURLs) < 1 { - return fmt.Errorf("Need at least one client URL to tunnel!") + return fmt.Errorf("need at least one client URL to tunnel") } if len(obj.remoteURLs) < 1 { - return fmt.Errorf("Need at least one remote URL to tunnel!") + return fmt.Errorf("need at least one remote URL to tunnel") } // TODO: do something less arbitrary about which one we pick? @@ -477,10 +477,10 @@ func (obj *SSH) TunnelClose() error { // Exec runs the binary on the remote server. func (obj *SSH) Exec() error { if obj.execpath == "" { - return fmt.Errorf("Must have a binary path to execute!") + return fmt.Errorf("must have a binary path to execute") } if obj.filepath == "" { - return fmt.Errorf("Must have a graph definition to run!") + return fmt.Errorf("must have a graph definition to run") } var err error @@ -772,7 +772,7 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) { } host = x[0] if host == "" { - return nil, fmt.Errorf("Empty hostname!") + return nil, fmt.Errorf("empty hostname") } user := defaultUser // default @@ -795,7 +795,7 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) { } if len(auth) == 0 { - return nil, fmt.Errorf("No authentication methods available!") + return nil, fmt.Errorf("no authentication methods available") } //hostname := config.Hostname // TODO: optionally specify local hostname somehow @@ -804,7 +804,7 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) { hostname = host // default to above } if util.StrInList(hostname, obj.hostnames) { - return nil, fmt.Errorf("Remote: Hostname `%s` already exists!", hostname) + return nil, fmt.Errorf("Remote: Hostname `%s` already exists", hostname) } obj.hostnames = append(obj.hostnames, hostname) @@ -830,7 +830,7 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) { // sshKeyAuth is a helper function to get the ssh key auth struct needed func (obj *Remotes) sshKeyAuth() (ssh.AuthMethod, error) { if obj.sshPrivIdRsa == "" { - return nil, fmt.Errorf("Empty path specified!") + return nil, fmt.Errorf("empty path specified") } p := "" // TODO: this doesn't match strings of the form: ~james/.ssh/id_rsa @@ -843,7 +843,7 @@ func (obj *Remotes) sshKeyAuth() (ssh.AuthMethod, error) { p = path.Join(usr.HomeDir, obj.sshPrivIdRsa[len("~/"):]) } if p == "" { - return nil, fmt.Errorf("Empty path specified!") + return nil, fmt.Errorf("empty path specified") } // A public key may be used to authenticate against the server by using // an unencrypted PEM-encoded private key file. If you have an encrypted @@ -892,7 +892,7 @@ func (obj *Remotes) passwordCallback(user, host string) func() (string, error) { case e := <-failchan: return "", e case <-util.TimeAfterOrBlock(timeout): - return "", fmt.Errorf("Interactive timeout reached!") + return "", fmt.Errorf("interactive timeout reached") } } return cb diff --git a/yamlgraph/gconfig.go b/yamlgraph/gconfig.go index 3a4968e3..933d824a 100644 --- a/yamlgraph/gconfig.go +++ b/yamlgraph/gconfig.go @@ -34,10 +34,6 @@ import ( "gopkg.in/yaml.v2" ) -const ( - Debug = false // FIXME: integrate with global debug flag -) - type collectorResConfig struct { Kind string `yaml:"kind"` Pattern string `yaml:"pattern"` // XXX: Not Implemented @@ -120,9 +116,6 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world gapi.World, noop slice := reflect.ValueOf(iface) // XXX: should we just drop these everywhere and have the kind strings be all lowercase? kind := util.FirstToUpper(name) - if Debug { - log.Printf("Config: Processing: %v...", kind) - } for j := 0; j < slice.Len(); j++ { // loop through resources of same kind x := slice.Index(j).Interface() res, ok := x.(resources.Res) // convert to Res type