Add thread-safe Add/Del methods and refactor client locking
- Add Add and Del methods to Client for dynamic host management. - Add RWMutex to Client to protect the devices map. - Add Transport to Config to allow mocking HTTP transport in tests. - Add getDeviceByHost helper to centralize device lookup locking. - Refactor GetAll* methods to snapshot host keys before iteration to avoid concurrent map read/write panic. - Add tests for thread safety and Add/Del functionality.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package edgeos
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Config represents the configuration for an EdgeOS device.
|
||||
type Config struct {
|
||||
@@ -10,4 +13,6 @@ type Config struct {
|
||||
Username string
|
||||
Password string
|
||||
Timeout time.Duration
|
||||
// Transport allows customizing the http transport (useful for testing)
|
||||
Transport http.RoundTripper
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user