feat: support checking supported and enabled controller features (#41)

* feat: support checking supported and enabled controller features

* linting
This commit is contained in:
Mateusz Filipowicz
2025-03-02 22:22:18 +01:00
committed by GitHub
parent 4e6e9d97b7
commit a5955a6358
7 changed files with 291 additions and 1 deletions

View File

@@ -113,4 +113,35 @@ if err != nil {
for _, network := range networks {
fmt.Printf("Network: %s\n", network.Name)
}
```
```
## Checking if features are supported and enabled
The UniFi Go SDK provides a way to check if a feature is supported and enabled/disabled on the UniFi Controller.
This can be useful when you want to check if a feature is available before using it. Passed feature names are case-insensitive.
**Example:**
```go
if c.IsFeatureEnabled(ctx, "default", "feature-name") {
// Feature is enabled
} else {
// Feature is disabled
}
```
Library comes with a set of predefined feature names, which can be found in `github.com/filipowm/go-unifi/unifi/features` module. You can also use custom feature names.
For example, you can check if the `features.ZoneBasedFirewallMigration` is available on the controller (no `unifi.ErrNotFound` raised) and enabled:
```go
f, err := c.GetFeature(ctx, "default", features.ZoneBasedFirewallMigration)
if err != nil {
if errors.Is(err, unifi.ErrNotFound) {
log.Printf("Feature %s unavailable (not found)", features.ZoneBasedFirewallMigration)
} else {
log.Fatalf("Error getting feature: %v", err)
}
return false
}
return f.FeatureExists // `FeatureExists` is a boolean indicating if the feature is enabled
```