Close cleans up the WireGuard manager and removes the interface
()
| 251 | |
| 252 | // Close cleans up the WireGuard manager and removes the interface |
| 253 | func (m *Manager) Close() error { |
| 254 | m.mu.Lock() |
| 255 | defer m.mu.Unlock() |
| 256 | |
| 257 | var errs []error |
| 258 | |
| 259 | client := m.client |
| 260 | m.client = nil |
| 261 | |
| 262 | // Close wgctrl client |
| 263 | if client != nil { |
| 264 | if err := client.Close(); err != nil { |
| 265 | errs = append(errs, fmt.Errorf("client close: %w", err)) |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // Remove interface |
| 270 | if err := m.cleanupExistingInterface(); err != nil { |
| 271 | errs = append(errs, err) |
| 272 | } |
| 273 | |
| 274 | if len(errs) > 0 { |
| 275 | return errors.Join(errs...) |
| 276 | } |
| 277 | return nil |
| 278 | } |
| 279 | |
| 280 | // cleanupExistingInterface removes existing interface if it exists |
| 281 | func (m *Manager) cleanupExistingInterface() error { |
nothing calls this directly
no test coverage detected