summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/agent/module/registry.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/go/collectors/go.d.plugin/agent/module/registry.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/agent/module/registry.go b/src/go/collectors/go.d.plugin/agent/module/registry.go
new file mode 100644
index 000000000..f2fa661c1
--- /dev/null
+++ b/src/go/collectors/go.d.plugin/agent/module/registry.go
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package module
+
+import "fmt"
+
+const (
+ UpdateEvery = 1
+ AutoDetectionRetry = 0
+ Priority = 70000
+)
+
+// Defaults is a set of module default parameters.
+type Defaults struct {
+ UpdateEvery int
+ AutoDetectionRetry int
+ Priority int
+ Disabled bool
+}
+
+type (
+ // Creator is a Job builder.
+ Creator struct {
+ Defaults
+ Create func() Module
+ JobConfigSchema string
+ }
+ // Registry is a collection of Creators.
+ Registry map[string]Creator
+)
+
+// DefaultRegistry DefaultRegistry.
+var DefaultRegistry = Registry{}
+
+// Register registers a module in the DefaultRegistry.
+func Register(name string, creator Creator) {
+ DefaultRegistry.Register(name, creator)
+}
+
+// Register registers a module.
+func (r Registry) Register(name string, creator Creator) {
+ if _, ok := r[name]; ok {
+ panic(fmt.Sprintf("%s is already in registry", name))
+ }
+ r[name] = creator
+}
+
+func (r Registry) Lookup(name string) (Creator, bool) {
+ v, ok := r[name]
+ return v, ok
+}