golint: Fix issues caught by the linter
This commit is contained in:
@@ -47,7 +47,7 @@ func NewConfigWatcher() *ConfigWatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Add method adds a new file path to watch for events on.
|
// Add new file paths to watch for events on.
|
||||||
func (obj *ConfigWatcher) Add(file ...string) {
|
func (obj *ConfigWatcher) Add(file ...string) {
|
||||||
if len(file) == 0 {
|
if len(file) == 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -23,8 +23,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//go:generate stringer -type=EventName -output=eventname_stringer.go
|
//go:generate stringer -type=EventName -output=eventname_stringer.go
|
||||||
|
|
||||||
|
// EventName represents the type of event being passed.
|
||||||
type EventName int
|
type EventName int
|
||||||
|
|
||||||
|
// The different event names are used in different contexts.
|
||||||
const (
|
const (
|
||||||
EventNil EventName = iota
|
EventNil EventName = iota
|
||||||
EventExit
|
EventExit
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
// Package global holds some global variables that are used throughout the code.
|
// Package global holds some global variables that are used throughout the code.
|
||||||
package global
|
package global
|
||||||
|
|
||||||
|
// These constants are used throughout the program.
|
||||||
const (
|
const (
|
||||||
DEBUG = false // add additional log messages
|
DEBUG = false // add additional log messages
|
||||||
TRACE = false // add execution flow log messages
|
TRACE = false // add execution flow log messages
|
||||||
|
|||||||
@@ -714,7 +714,7 @@ func (g *Graph) Worker(v *Vertex) error {
|
|||||||
<-timer.C // unnecessary, shouldn't happen
|
<-timer.C // unnecessary, shouldn't happen
|
||||||
}
|
}
|
||||||
var delay = time.Duration(v.Meta().Delay) * time.Millisecond
|
var delay = time.Duration(v.Meta().Delay) * time.Millisecond
|
||||||
var retry int16 = v.Meta().Retry // number of tries left, -1 for infinite
|
var retry = v.Meta().Retry // number of tries left, -1 for infinite
|
||||||
var saved event.Event
|
var saved event.Event
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
@@ -775,7 +775,7 @@ func (g *Graph) Worker(v *Vertex) error {
|
|||||||
// NOTE: we're using the same retry and delay metaparams that CheckApply
|
// NOTE: we're using the same retry and delay metaparams that CheckApply
|
||||||
// uses. This is for practicality. We can separate them later if needed!
|
// uses. This is for practicality. We can separate them later if needed!
|
||||||
var watchDelay time.Duration
|
var watchDelay time.Duration
|
||||||
var watchRetry int16 = v.Meta().Retry // number of tries left, -1 for infinite
|
var watchRetry = v.Meta().Retry // number of tries left, -1 for infinite
|
||||||
// watch blocks until it ends, & errors to retry
|
// watch blocks until it ends, & errors to retry
|
||||||
for {
|
for {
|
||||||
// TODO: do we have to stop the converged-timeout when in this block (perhaps we're in the delay block!)
|
// TODO: do we have to stop the converged-timeout when in this block (perhaps we're in the delay block!)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import (
|
|||||||
|
|
||||||
cv "github.com/purpleidea/mgmt/converger"
|
cv "github.com/purpleidea/mgmt/converger"
|
||||||
"github.com/purpleidea/mgmt/gconfig"
|
"github.com/purpleidea/mgmt/gconfig"
|
||||||
|
"github.com/purpleidea/mgmt/global"
|
||||||
"github.com/purpleidea/mgmt/util"
|
"github.com/purpleidea/mgmt/util"
|
||||||
|
|
||||||
"github.com/howeyc/gopass"
|
"github.com/howeyc/gopass"
|
||||||
@@ -72,7 +73,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DEBUG = false
|
|
||||||
// FIXME: should this dir be in /var/ instead?
|
// FIXME: should this dir be in /var/ instead?
|
||||||
formatPattern = "/tmp/mgmt.%s/" // remote format, to match `mktemp`
|
formatPattern = "/tmp/mgmt.%s/" // remote format, to match `mktemp`
|
||||||
formatChars = "abcdefghijklmnopqrstuvwxyz0123456789" // chars for fmt string // TODO: what does mktemp use?
|
formatChars = "abcdefghijklmnopqrstuvwxyz0123456789" // chars for fmt string // TODO: what does mktemp use?
|
||||||
@@ -143,7 +143,7 @@ func (obj *SSH) Close() error {
|
|||||||
return obj.client.Close()
|
return obj.client.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Sftp function uses the sftp protocol to create a remote dir and copy over
|
// Sftp is a function for the sftp protocol to create a remote dir and copy over
|
||||||
// the binary to run. On error the string represents the path to the remote dir.
|
// the binary to run. On error the string represents the path to the remote dir.
|
||||||
func (obj *SSH) Sftp() error {
|
func (obj *SSH) Sftp() error {
|
||||||
var err error
|
var err error
|
||||||
@@ -446,7 +446,7 @@ func (obj *SSH) forward(remoteConn net.Conn) net.Conn {
|
|||||||
log.Printf("Remote: io.Copy error: %s", err)
|
log.Printf("Remote: io.Copy error: %s", err)
|
||||||
// FIXME: what should we do here???
|
// FIXME: what should we do here???
|
||||||
}
|
}
|
||||||
if DEBUG {
|
if global.DEBUG {
|
||||||
log.Printf("Remote: io.Copy finished: %d", n)
|
log.Printf("Remote: io.Copy finished: %d", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -705,7 +705,7 @@ type Remotes struct {
|
|||||||
program string // name of the program
|
program string // name of the program
|
||||||
}
|
}
|
||||||
|
|
||||||
// The NewRemotes function builds a Remotes struct.
|
// NewRemotes builds a Remotes struct.
|
||||||
func NewRemotes(clientURLs, remoteURLs []string, noop bool, remotes []string, fileWatch chan string, cConns uint16, interactive bool, sshPrivIdRsa string, caching bool, depth uint16, prefix string, converger cv.Converger, convergerCb func(func(map[string]bool) error) (func(), error), program string) *Remotes {
|
func NewRemotes(clientURLs, remoteURLs []string, noop bool, remotes []string, fileWatch chan string, cConns uint16, interactive bool, sshPrivIdRsa string, caching bool, depth uint16, prefix string, converger cv.Converger, convergerCb func(func(map[string]bool) error) (func(), error), program string) *Remotes {
|
||||||
return &Remotes{
|
return &Remotes{
|
||||||
clientURLs: clientURLs,
|
clientURLs: clientURLs,
|
||||||
@@ -890,8 +890,7 @@ func (obj *Remotes) passwordCallback(user, host string) func() (string, error) {
|
|||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Run method of the Remotes struct kicks it all off. It is usually run from
|
// Run kicks it all off. It is usually run from a go routine.
|
||||||
// a go routine.
|
|
||||||
func (obj *Remotes) Run() {
|
func (obj *Remotes) Run() {
|
||||||
// TODO: we can disable a lot of this if we're not using --converged-timeout
|
// TODO: we can disable a lot of this if we're not using --converged-timeout
|
||||||
// link in all the converged timeout checking and callbacks...
|
// link in all the converged timeout checking and callbacks...
|
||||||
@@ -922,7 +921,7 @@ func (obj *Remotes) Run() {
|
|||||||
if !ok { // no status on hostname means unconverged!
|
if !ok { // no status on hostname means unconverged!
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if DEBUG {
|
if global.DEBUG {
|
||||||
log.Printf("Remote: Converged: Status: %+v", obj.converger.Status())
|
log.Printf("Remote: Converged: Status: %+v", obj.converger.Status())
|
||||||
}
|
}
|
||||||
// if exiting, don't update, it will be unregistered...
|
// if exiting, don't update, it will be unregistered...
|
||||||
@@ -1016,8 +1015,8 @@ func (obj *Remotes) Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Exit method causes as much of the Remotes struct to shutdown as quickly
|
// Exit causes as much of the Remotes struct to shutdown as quickly and as
|
||||||
// and as cleanly as possible. It only returns once everything is shutdown.
|
// cleanly as possible. It only returns once everything is shutdown.
|
||||||
func (obj *Remotes) Exit() {
|
func (obj *Remotes) Exit() {
|
||||||
obj.lock.Lock()
|
obj.lock.Lock()
|
||||||
obj.exiting = true // don't spawn new ones once this flag is set!
|
obj.exiting = true // don't spawn new ones once this flag is set!
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func (obj *ExecRes) Validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// wraps the scanner output in a channel
|
// BufioChanScanner wraps the scanner output in a channel.
|
||||||
func (obj *ExecRes) BufioChanScanner(scanner *bufio.Scanner) (chan string, chan error) {
|
func (obj *ExecRes) BufioChanScanner(scanner *bufio.Scanner) (chan string, chan error) {
|
||||||
ch, errch := make(chan string), make(chan error)
|
ch, errch := make(chan string), make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
@@ -348,8 +348,7 @@ type ExecUUID struct {
|
|||||||
// TODO: add more elements here
|
// TODO: add more elements here
|
||||||
}
|
}
|
||||||
|
|
||||||
// if and only if they are equivalent, return true
|
// IFF aka if and only if they are equivalent, return true. If not, false.
|
||||||
// if they are not equivalent, return false
|
|
||||||
func (obj *ExecUUID) IFF(uuid ResUUID) bool {
|
func (obj *ExecUUID) IFF(uuid ResUUID) bool {
|
||||||
res, ok := uuid.(*ExecUUID)
|
res, ok := uuid.(*ExecUUID)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -383,7 +382,7 @@ func (obj *ExecUUID) IFF(uuid ResUUID) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// The AutoEdges method returns the AutoEdges. In this case none are used.
|
// AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
|
||||||
func (obj *ExecRes) AutoEdges() AutoEdge {
|
func (obj *ExecRes) AutoEdges() AutoEdge {
|
||||||
// TODO: parse as many exec params to look for auto edges, for example
|
// TODO: parse as many exec params to look for auto edges, for example
|
||||||
// the path of the binary in the Cmd variable might be from in a pkg
|
// the path of the binary in the Cmd variable might be from in a pkg
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (obj *NoopRes) Init() error {
|
|||||||
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
return obj.BaseRes.Init() // call base init, b/c we're overriding
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate if the params passed in are valid data
|
// Validate if the params passed in are valid data.
|
||||||
// FIXME: where should this get called ?
|
// FIXME: where should this get called ?
|
||||||
func (obj *NoopRes) Validate() error {
|
func (obj *NoopRes) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
@@ -124,7 +124,7 @@ type NoopUUID struct {
|
|||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
// The AutoEdges method returns the AutoEdges. In this case none are used.
|
// AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
|
||||||
func (obj *NoopRes) AutoEdges() AutoEdge {
|
func (obj *NoopRes) AutoEdges() AutoEdge {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,8 +369,7 @@ type PkgUUID struct {
|
|||||||
state string // pkg state or "version"
|
state string // pkg state or "version"
|
||||||
}
|
}
|
||||||
|
|
||||||
// if and only if they are equivalent, return true
|
// IFF aka if and only if they are equivalent, return true. If not, false.
|
||||||
// if they are not equivalent, return false
|
|
||||||
func (obj *PkgUUID) IFF(uuid ResUUID) bool {
|
func (obj *PkgUUID) IFF(uuid ResUUID) bool {
|
||||||
res, ok := uuid.(*PkgUUID)
|
res, ok := uuid.(*PkgUUID)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -562,7 +561,7 @@ func (obj *PkgRes) Compare(res Res) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a list of svc names for matches like /usr/lib/systemd/system/*.service
|
// ReturnSvcInFileList returns a list of svc names for matches like: `/usr/lib/systemd/system/*.service`.
|
||||||
func ReturnSvcInFileList(fileList []string) []string {
|
func ReturnSvcInFileList(fileList []string) []string {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
for _, x := range fileList {
|
for _, x := range fileList {
|
||||||
|
|||||||
@@ -31,8 +31,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//go:generate stringer -type=ResState -output=resstate_stringer.go
|
//go:generate stringer -type=ResState -output=resstate_stringer.go
|
||||||
|
|
||||||
|
// The ResState type represents the current activity state of each resource.
|
||||||
type ResState int
|
type ResState int
|
||||||
|
|
||||||
|
// Each ResState should be set properly in the relevant part of the resource.
|
||||||
const (
|
const (
|
||||||
ResStateNil ResState = iota
|
ResStateNil ResState = iota
|
||||||
ResStateWatching
|
ResStateWatching
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func TestReadEvent(t *testing.T) {
|
|||||||
eventExit: false,
|
eventExit: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
for event, _ := range shouldExit {
|
for event := range shouldExit {
|
||||||
exit, poke := res.ReadEvent(&Event{Name: event})
|
exit, poke := res.ReadEvent(&Event{Name: event})
|
||||||
if exit != shouldExit[event] {
|
if exit != shouldExit[event] {
|
||||||
t.Errorf("resource.ReadEvent returned wrong exit flag for a %v event (%v, should be %v)",
|
t.Errorf("resource.ReadEvent returned wrong exit flag for a %v event (%v, should be %v)",
|
||||||
|
|||||||
@@ -362,8 +362,7 @@ type SvcUUID struct {
|
|||||||
name string // the svc name
|
name string // the svc name
|
||||||
}
|
}
|
||||||
|
|
||||||
// if and only if they are equivalent, return true
|
// IFF aka if and only if they are equivalent, return true. If not, false.
|
||||||
// if they are not equivalent, return false
|
|
||||||
func (obj *SvcUUID) IFF(uuid ResUUID) bool {
|
func (obj *SvcUUID) IFF(uuid ResUUID) bool {
|
||||||
res, ok := uuid.(*SvcUUID)
|
res, ok := uuid.(*SvcUUID)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -411,7 +410,7 @@ func (obj *SvcResAutoEdges) Test(input []bool) bool {
|
|||||||
return true // keep going
|
return true // keep going
|
||||||
}
|
}
|
||||||
|
|
||||||
// The AutoEdges method returns the AutoEdges. In this case the systemd units.
|
// AutoEdges returns the AutoEdge interface. In this case the systemd units.
|
||||||
func (obj *SvcRes) AutoEdges() AutoEdge {
|
func (obj *SvcRes) AutoEdges() AutoEdge {
|
||||||
var data []ResUUID
|
var data []ResUUID
|
||||||
svcFiles := []string{
|
svcFiles := []string{
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func (obj *TimerRes) GetUUIDs() []ResUUID {
|
|||||||
return []ResUUID{x}
|
return []ResUUID{x}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The AutoEdges method returns the AutoEdges. In this case none are used.
|
// AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
|
||||||
func (obj *TimerRes) AutoEdges() AutoEdge {
|
func (obj *TimerRes) AutoEdges() AutoEdge {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user