From 5c72967fd8e84c3f3a6503ca62c1950939cbeed4 Mon Sep 17 00:00:00 2001 From: Pascal Mathis Date: Mon, 29 Apr 2019 15:25:32 +0200 Subject: [PATCH] various: Add missing docstrings to fix linter error --- mod-frrouting/init.go | 3 ++- mod-system/init.go | 1 + nagocheck/kingpin.go | 1 + nagocheck/module.go | 9 +++++++-- nagocheck/plugin.go | 6 ++++++ nagocheck/resource.go | 4 ++++ nagocheck/summarizer.go | 3 +++ 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/mod-frrouting/init.go b/mod-frrouting/init.go index 07d527b..9feed5c 100644 --- a/mod-frrouting/init.go +++ b/mod-frrouting/init.go @@ -35,7 +35,8 @@ type frroutingModule struct { TelnetPassword string } -func NewFrroutingModule() *frroutingModule { +// NewFrroutingModule instantiates frroutingModule and all contained plugins +func NewFrroutingModule() nagocheck.Module { return &frroutingModule{ Module: nagocheck.NewModule("frrouting", nagocheck.ModuleDescription("FRRouting"), diff --git a/mod-system/init.go b/mod-system/init.go index 4d095be..c784827 100644 --- a/mod-system/init.go +++ b/mod-system/init.go @@ -24,6 +24,7 @@ type systemModule struct { nagocheck.Module } +// NewSystemModule instantiates systemModule and all contained plugins func NewSystemModule() nagocheck.Module { return &systemModule{ Module: nagocheck.NewModule("system", diff --git a/nagocheck/kingpin.go b/nagocheck/kingpin.go index edab79c..d69da04 100644 --- a/nagocheck/kingpin.go +++ b/nagocheck/kingpin.go @@ -5,6 +5,7 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) +// KingpinNode is a unified interface for kingpin, which allows using Arg() and Flag() at root- and command-level type KingpinNode interface { Arg(name, help string) *kingpin.ArgClause Flag(name, help string) *kingpin.FlagClause diff --git a/nagocheck/module.go b/nagocheck/module.go index 80ba4ab..302862e 100644 --- a/nagocheck/module.go +++ b/nagocheck/module.go @@ -24,7 +24,7 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) -// Module collects several plugin commands underneath a module command and offers the possibility to define CLI flags +// Module consists out of several plugins and offers methods for executing them type Module interface { Name() string Description() string @@ -37,6 +37,7 @@ type Module interface { GetPluginByName(pluginName string) (Plugin, error) } +// ModuleOpt is a type alias for functional options used by NewModule() type ModuleOpt func(*baseModule) type baseModule struct { @@ -45,6 +46,8 @@ type baseModule struct { plugins map[string]Plugin } +// RegisterModules returns a map of modules with their name as the respective key. Additionally, all plugins contained +// by these modules are being registered to their respective module using Plugin.setModule() func RegisterModules(modules ...Module) map[string]Module { result := make(map[string]Module) for _, module := range modules { @@ -57,7 +60,7 @@ func RegisterModules(modules ...Module) map[string]Module { return result } -// NewModule instantiates a new baseModule, which should be inherited by user-defined module types +// NewModule instantiates baseModule with the given functional options func NewModule(name string, options ...ModuleOpt) Module { module := &baseModule{ name: name, @@ -72,12 +75,14 @@ func NewModule(name string, options ...ModuleOpt) Module { return module } +// ModuleDescription is a functional option for NewModule(), which sets the module description func ModuleDescription(description string) ModuleOpt { return func(m *baseModule) { m.description = description } } +// ModulePlugin is a functional option for NewModule(), which registers a plugin using Module.RegisterPlugin() func ModulePlugin(plugin Plugin) ModuleOpt { return func(m *baseModule) { m.RegisterPlugin(plugin) diff --git a/nagocheck/plugin.go b/nagocheck/plugin.go index 311b101..ba840c0 100644 --- a/nagocheck/plugin.go +++ b/nagocheck/plugin.go @@ -4,6 +4,7 @@ import ( "github.com/snapserv/nagopher" ) +// Plugin represents a single check including its CLI arguments type Plugin interface { Name() string Description() string @@ -19,6 +20,7 @@ type Plugin interface { defineDefaultFlags(node KingpinNode) } +// PluginOpt is a type alias for functional options used by NewPlugin() type PluginOpt func(*basePlugin) type basePlugin struct { @@ -33,6 +35,7 @@ type basePlugin struct { criticalThreshold nagopher.OptionalBounds } +// NewPlugin instantiates basePlugin with the given functional options func NewPlugin(name string, options ...PluginOpt) Plugin { plugin := &basePlugin{ name: name, @@ -48,18 +51,21 @@ func NewPlugin(name string, options ...PluginOpt) Plugin { return plugin } +// PluginDescription is a functional option for NewPlugin(), which sets the module description func PluginDescription(description string) PluginOpt { return func(p *basePlugin) { p.description = description } } +// PluginDefaultFlags is a functional option for NewPlugin(), which toggles the definition of default flags func PluginDefaultFlags(enabled bool) PluginOpt { return func(p *basePlugin) { p.useDefaultFlags = enabled } } +// PluginDefaultThresholds is a functional option for NewPlugin(), which toggles the definition of default thresholds func PluginDefaultThresholds(enabled bool) PluginOpt { return func(p *basePlugin) { p.useDefaultThresholds = enabled diff --git a/nagocheck/resource.go b/nagocheck/resource.go index 7aebf37..3d40595 100644 --- a/nagocheck/resource.go +++ b/nagocheck/resource.go @@ -10,11 +10,13 @@ import ( "syscall" ) +// Resource provides a base type for nagocheck resources, which embeds nagopher.Resource type Resource interface { nagopher.Resource Plugin() Plugin } +// ResourceOpt is a type alias for functional options used by NewSummarizer() type ResourceOpt func(*baseResource) type baseResource struct { @@ -27,6 +29,7 @@ type baseResource struct { const shmOpenFlags = os.O_CREATE | os.O_RDONLY | syscall.O_DSYNC | syscall.O_RSYNC const shmDefaultMode = 0600 +// NewResource instantiates baseResource with the given functional options func NewResource(plugin Plugin, options ...ResourceOpt) Resource { resource := &baseResource{ Resource: nagopher.NewResource(), @@ -40,6 +43,7 @@ func NewResource(plugin Plugin, options ...ResourceOpt) Resource { return resource } +// ResourcePersistence is a functional option for NewResource(), which enables resource persistence with the given key func ResourcePersistence(uniqueKey string) ResourceOpt { return func(r *baseResource) { r.persistenceKey = r.Plugin().Name() + uniqueKey diff --git a/nagocheck/summarizer.go b/nagocheck/summarizer.go index c12a529..b2b4b78 100644 --- a/nagocheck/summarizer.go +++ b/nagocheck/summarizer.go @@ -2,11 +2,13 @@ package nagocheck import "github.com/snapserv/nagopher" +// Summarizer provides a base type for nagocheck summarizers, which embeds nagopher.Summarizer type Summarizer interface { nagopher.Summarizer Plugin() Plugin } +// SummarizerOpt is a type alias for functional options used by NewSummarizer() type SummarizerOpt func(*baseSummarizer) type baseSummarizer struct { @@ -14,6 +16,7 @@ type baseSummarizer struct { plugin Plugin } +// NewSummarizer instantiates baseSummarizer with the given functional options func NewSummarizer(plugin Plugin, options ...SummarizerOpt) Summarizer { summarizer := &baseSummarizer{ Summarizer: nagopher.NewSummarizer(),