Add adds and initializes a new hook.
(hook Hook, config any)
| 150 | |
| 151 | // Add adds and initializes a new hook. |
| 152 | func (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. |
| 175 | func (h *Hooks) GetAll() []Hook { |