Go SDK for interaction with NetScaler ADC (VPX/MPX/BLX)
go get github.com/jantytgat/go-netscaleradcpackage main
import (
"context"
"fmt"
"log"
"github.com/jantytgat/go-netscaleradc/adc"
)
func main() {
// Create the API client
client, err := adc.NewApiClient(
"my-netscaler", // Name (for identification)
"192.168.1.10:443", // Address with port
adc.ApiCredentials{
Username: "nsroot",
Password: "nsroot",
},
adc.ApiConnectionSettings{
UseSsl: true,
Timeout: 5,
ValidateServerCertificate: false,
AutoLogin: true,
},
adc.StrictSerializationMode,
)
if err != nil {
log.Fatal(err)
}
defer client.Logout()
ctx := context.Background()
// Get system configuration
config, err := client.NsConfig.Get(ctx, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Primary IP: %s\n", config.PrimaryIp)
// Save configuration
if err := client.SaveConfig(ctx); err != nil {
log.Fatal(err)
}
}| Setting | Description |
|---|---|
UseSsl |
Use HTTPS instead of HTTP |
Timeout |
Request timeout in seconds (0 = default 5s) |
ValidateServerCertificate |
Validate TLS certificate |
AutoLogin |
Automatically login when creating client |
UserAgent |
Custom User-Agent header |
LogTlsSecrets |
Log TLS session keys for debugging |
StrictSerializationMode- Fails on unknown JSON fields (recommended)LooseSerializationMode- Ignores unknown JSON fields
Access NetScaler resources through typed handlers:
client.NsConfig // System configuration
client.HaNode // HA node management
client.HaFailOver // HA failover operations
client.NsReboot // System reboot
client.NsShutdown // System shutdown// Check if connected to primary HA node
isPrimary, _ := client.IsPrimaryNode(ctx)
// Save running configuration
client.SaveConfig(ctx)
// Force HA failover
client.FailOver(ctx)
// Reboot (warm=true for software-only restart)
client.Reboot(ctx, true)
// Shutdown
client.Shutdown(ctx)Run all tests:
go test ./...Run tests for a specific package:
go test ./adcnitro/...Run a specific test:
go test ./adcnitro/... -run TestHaNodeHandler_GetThe adc package includes comprehensive tests organized by component:
| File | Coverage |
|---|---|
error_test.go |
Error handling, wrapping, and matching |
apiConnectionSettings_test.go |
Connection settings, URL scheme, timeouts |
apiClient_test.go |
Client creation, login/logout, headers |
request_test.go |
Request validation, URL building, serialization |
response_test.go |
Response deserialization, data extraction |
api_test.go |
Generic CRUD operations |
resourceTag_test.go |
Struct tag parsing |
handler_hanode_test.go |
HA node handler operations |
handler_nsconfig_test.go |
NS config handler operations |
handler_reboot_test.go |
Reboot handler |
handler_shutdown_test.go |
Shutdown handler |
handler_hafailover_test.go |
HA failover handler |
Tests use httptest.Server to mock the NITRO API without requiring a live NetScaler instance.