Skip to content

Commit

Permalink
various: Add missing docstrings to fix linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
ppmathis committed Apr 29, 2019
1 parent 81a1f68 commit 5c72967
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mod-frrouting/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions mod-system/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions nagocheck/kingpin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions nagocheck/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions nagocheck/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions nagocheck/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions nagocheck/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ 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 {
nagopher.Summarizer
plugin Plugin
}

// NewSummarizer instantiates baseSummarizer with the given functional options
func NewSummarizer(plugin Plugin, options ...SummarizerOpt) Summarizer {
summarizer := &baseSummarizer{
Summarizer: nagopher.NewSummarizer(),
Expand Down

0 comments on commit 5c72967

Please sign in to comment.