| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package dyncfg |
| 4 | |
| 5 | import "github.com/netdata/netdata/go/plugins/plugin/framework/functions" |
| 6 | |
| 7 | // WrapHandler adapts a dyncfg function handler to functions.Registry handler type. |
| 8 | func WrapHandler(handler func(Function)) func(functions.Function) { |
| 9 | return func(fn functions.Function) { |
| 10 | handler(NewFunction(fn)) |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | // BindResponder swaps a component responder and keeps handler API in sync. |
| 15 | func BindResponder[C Config](dst **Responder, handler *Handler[C], responder *Responder) { |
| 16 | if responder == nil { |
| 17 | // Nil means "keep the current responder" rather than clearing output wiring. |
| 18 | return |
| 19 | } |
| 20 | *dst = responder |
| 21 | if handler != nil { |
| 22 | handler.SetAPI(responder) |
| 23 | } |
| 24 | } |