golint: Fix some golint issues

This commit is contained in:
James Shubin
2016-12-21 03:10:25 -05:00
parent b3ea33f88d
commit 19760be0bc
6 changed files with 21 additions and 26 deletions

View File

@@ -316,7 +316,7 @@ func (obj *EmbdEtcd) Connect(reconnect bool) error {
if emax > maxClientConnectRetries { if emax > maxClientConnectRetries {
log.Printf("Etcd: The dataDir (%s) might be inconsistent or corrupt.", obj.dataDir) 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") 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 return obj.cError
} }
err = &CtxDelayErr{time.Duration(emax) * time.Second, "No endpoints available yet!"} // retry with backoff... err = &CtxDelayErr{time.Duration(emax) * time.Second, "No endpoints available yet!"} // retry with backoff...

View File

@@ -86,7 +86,7 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
Name: "file1", Name: "file1",
// send->recv! // send->recv!
Recv: map[string]*resources.Send{ Recv: map[string]*resources.Send{
"Content": &resources.Send{Res: p1, Key: "Password"}, "Content": {Res: p1, Key: "Password"},
}, },
}, },
Path: "/tmp/mgmt/secret", Path: "/tmp/mgmt/secret",

View File

@@ -40,6 +40,7 @@ const (
graphStatePaused graphStatePaused
) )
// Flags contains specific constants used by the graph.
type Flags struct { type Flags struct {
Debug bool Debug bool
} }

View File

@@ -32,7 +32,8 @@ import (
const ( const (
// PuppetYAMLBufferSize is the maximum buffer size for the yaml input data // PuppetYAMLBufferSize is the maximum buffer size for the yaml input data
PuppetYAMLBufferSize = 65535 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) { func runPuppetCommand(cmd *exec.Cmd) ([]byte, error) {

View File

@@ -156,11 +156,11 @@ func (obj *SSH) Sftp() error {
var err error var err error
if obj.client == nil { 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! // this check is needed because the golang path.Base function is weird!
if strings.HasSuffix(obj.file, "/") { 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... // 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 // make file executable; don't cache this in case it didn't ever happen
// TODO: do we want the group or other bits set? // TODO: do we want the group or other bits set?
if err := obj.sftp.Chmod(obj.execpath, 0770); err != nil { 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 // copy graph file
@@ -273,7 +273,7 @@ func (obj *SSH) Sftp() error {
// SftpGraphCopy is a helper function used for re-copying the graph definition. // SftpGraphCopy is a helper function used for re-copying the graph definition.
func (obj *SSH) SftpGraphCopy() (int64, error) { func (obj *SSH) SftpGraphCopy() (int64, error) {
if obj.filepath == "" { 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) 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. // SftpCopy is a simple helper function that runs a local -> remote sftp copy.
func (obj *SSH) SftpCopy(src, dst string) (int64, error) { func (obj *SSH) SftpCopy(src, dst string) (int64, error) {
if obj.sftp == nil { 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 var err error
// TODO: add a check to make sure we don't run two copies of this // 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) return n, fmt.Errorf("Can't copy to remote path: %v", err)
} }
if n <= 0 { if n <= 0 {
return n, fmt.Errorf("Zero bytes copied!") return n, fmt.Errorf("zero bytes copied")
} }
return n, nil return n, nil
} }
@@ -391,10 +391,10 @@ func (obj *SSH) Tunnel() error {
var err error var err error
if len(obj.clientURLs) < 1 { 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 { 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? // 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. // Exec runs the binary on the remote server.
func (obj *SSH) Exec() error { func (obj *SSH) Exec() error {
if obj.execpath == "" { 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 == "" { 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 var err error
@@ -772,7 +772,7 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) {
} }
host = x[0] host = x[0]
if host == "" { if host == "" {
return nil, fmt.Errorf("Empty hostname!") return nil, fmt.Errorf("empty hostname")
} }
user := defaultUser // default user := defaultUser // default
@@ -795,7 +795,7 @@ func (obj *Remotes) NewSSH(file string) (*SSH, error) {
} }
if len(auth) == 0 { 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 //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 hostname = host // default to above
} }
if util.StrInList(hostname, obj.hostnames) { 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) 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 // sshKeyAuth is a helper function to get the ssh key auth struct needed
func (obj *Remotes) sshKeyAuth() (ssh.AuthMethod, error) { func (obj *Remotes) sshKeyAuth() (ssh.AuthMethod, error) {
if obj.sshPrivIdRsa == "" { if obj.sshPrivIdRsa == "" {
return nil, fmt.Errorf("Empty path specified!") return nil, fmt.Errorf("empty path specified")
} }
p := "" p := ""
// TODO: this doesn't match strings of the form: ~james/.ssh/id_rsa // 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("~/"):]) p = path.Join(usr.HomeDir, obj.sshPrivIdRsa[len("~/"):])
} }
if p == "" { 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 // 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 // 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: case e := <-failchan:
return "", e return "", e
case <-util.TimeAfterOrBlock(timeout): case <-util.TimeAfterOrBlock(timeout):
return "", fmt.Errorf("Interactive timeout reached!") return "", fmt.Errorf("interactive timeout reached")
} }
} }
return cb return cb

View File

@@ -34,10 +34,6 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
const (
Debug = false // FIXME: integrate with global debug flag
)
type collectorResConfig struct { type collectorResConfig struct {
Kind string `yaml:"kind"` Kind string `yaml:"kind"`
Pattern string `yaml:"pattern"` // XXX: Not Implemented 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) slice := reflect.ValueOf(iface)
// XXX: should we just drop these everywhere and have the kind strings be all lowercase? // XXX: should we just drop these everywhere and have the kind strings be all lowercase?
kind := util.FirstToUpper(name) 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 for j := 0; j < slice.Len(); j++ { // loop through resources of same kind
x := slice.Index(j).Interface() x := slice.Index(j).Interface()
res, ok := x.(resources.Res) // convert to Res type res, ok := x.(resources.Res) // convert to Res type