summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/agent/functions/ext.go
blob: 28c717d888258dcac4e5a788eee11f5dd97047fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: GPL-3.0-or-later

package functions

func (m *Manager) Register(name string, fn func(Function)) {
	if fn == nil {
		m.Warningf("not registering '%s': nil function", name)
		return
	}

	m.mux.Lock()
	defer m.mux.Unlock()

	if _, ok := m.FunctionRegistry[name]; !ok {
		m.Debugf("registering function '%s'", name)
	} else {
		m.Warningf("re-registering function '%s'", name)
	}
	m.FunctionRegistry[name] = fn
}

func (m *Manager) Unregister(name string) {
	m.mux.Lock()
	defer m.mux.Unlock()

	if _, ok := m.FunctionRegistry[name]; !ok {
		delete(m.FunctionRegistry, name)
		m.Debugf("unregistering function '%s'", name)
	}
}