MCPcopy
hub / github.com/mochi-mqtt/server / Add

Method Add

hooks.go:152–172  ·  view source on GitHub ↗

Add adds and initializes a new hook.

(hook Hook, config any)

Source from the content-addressed store, hash-verified

150
151// Add adds and initializes a new hook.
152func (h *Hooks) Add(hook Hook, config any) error {
153 h.Lock()
154 defer h.Unlock()
155
156 err := hook.Init(config)
157 if err != nil {
158 return fmt.Errorf("failed initialising %s hook: %w", hook.ID(), err)
159 }
160
161 i, ok := h.internal.Load().([]Hook)
162 if !ok {
163 i = []Hook{}
164 }
165
166 i = append(i, hook)
167 h.internal.Store(i)
168 atomic.AddInt64(&h.qty, 1)
169 h.wg.Add(1)
170
171 return nil
172}
173
174// GetAll returns a slice of all the hooks.
175func (h *Hooks) GetAll() []Hook {

Callers 15

TestHooksProvidesFunction · 0.45
TestHooksAddLenGetAllFunction · 0.45
TestHooksAddInitFailureFunction · 0.45
TestHooksStopFunction · 0.45
TestHooksNonReturnsFunction · 0.45
TestHooksOnACLCheckFunction · 0.45
TestHooksOnSubscribeFunction · 0.45
TestHooksOnUnsubscribeFunction · 0.45
TestHooksOnPublishFunction · 0.45
TestHooksOnPacketReadFunction · 0.45

Calls 3

InitMethod · 0.65
IDMethod · 0.65
ErrorfMethod · 0.45

Tested by 15

TestHooksProvidesFunction · 0.36
TestHooksAddLenGetAllFunction · 0.36
TestHooksAddInitFailureFunction · 0.36
TestHooksStopFunction · 0.36
TestHooksNonReturnsFunction · 0.36
TestHooksOnACLCheckFunction · 0.36
TestHooksOnSubscribeFunction · 0.36
TestHooksOnUnsubscribeFunction · 0.36
TestHooksOnPublishFunction · 0.36
TestHooksOnPacketReadFunction · 0.36