rename to toughswitch
This commit is contained in:
@@ -21,4 +21,4 @@ All notable changes to this project will be documented in this file.
|
|||||||
## [v0.1.0] - 2026-01-04
|
## [v0.1.0] - 2026-01-04
|
||||||
### Added
|
### Added
|
||||||
- Initial CI pipeline setup.
|
- Initial CI pipeline setup.
|
||||||
- Initial release of Ubiquiti EdgeOS Go Client.
|
- Initial release of Ubiquiti toughswitch Go Client.
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -1,6 +1,7 @@
|
|||||||
# edgeos
|
# toughswitch
|
||||||
|
|
||||||
A Go client library for interacting with Ubiquiti EdgeOS devices (specifically tested with EdgeSwitch XP / ToughSwitch) via their internal REST API.
|
A Go client library for interacting with Ubiquiti toughswitch devices (specifically tested with
|
||||||
|
ToughSwitch POE Pro (TS-8-PRO)) via their internal REST API.
|
||||||
|
|
||||||
**⚠️ Disclaimer: This library is based on reverse-engineered API calls. It is not an official Ubiquiti product and is subject to change if the device firmware changes.**
|
**⚠️ Disclaimer: This library is based on reverse-engineered API calls. It is not an official Ubiquiti product and is subject to change if the device firmware changes.**
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ A Go client library for interacting with Ubiquiti EdgeOS devices (specifically t
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get gitea.libretechconsulting.com/rmcguire/edgeos-client/pkg/edgeos
|
go get gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/toughswitch
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -35,14 +36,14 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.libretechconsulting.com/rmcguire/edgeos-client/pkg/edgeos"
|
"gitea.libretechconsulting.com/rmcguire/toughswitch-client/pkg/toughswitch"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// Configure your device(s)
|
// Configure your device(s)
|
||||||
configs := []edgeos.Config{
|
configs := []toughswitch.Config{
|
||||||
{
|
{
|
||||||
Host: "192.168.1.1",
|
Host: "192.168.1.1",
|
||||||
Username: "ubnt",
|
Username: "ubnt",
|
||||||
@@ -53,7 +54,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the client
|
// Initialize the client
|
||||||
client := edgeos.MustNew(ctx, configs)
|
client := toughswitch.MustNew(ctx, configs)
|
||||||
|
|
||||||
// Fetch system information
|
// Fetch system information
|
||||||
deviceHost := "192.168.1.1"
|
deviceHost := "192.168.1.1"
|
||||||
@@ -108,11 +109,11 @@ for _, stat := range stats {
|
|||||||
The client is designed to handle multiple devices concurrently.
|
The client is designed to handle multiple devices concurrently.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
configs := []edgeos.Config{
|
configs := []toughswitch.Config{
|
||||||
{Host: "192.168.1.1", ...},
|
{Host: "192.168.1.1", ...},
|
||||||
{Host: "192.168.1.2", ...},
|
{Host: "192.168.1.2", ...},
|
||||||
}
|
}
|
||||||
client := edgeos.MustNew(ctx, configs)
|
client := toughswitch.MustNew(ctx, configs)
|
||||||
|
|
||||||
// Get info for all configured devices in parallel
|
// Get info for all configured devices in parallel
|
||||||
allSystems, err := client.GetAllSystems(ctx)
|
allSystems, err := client.GetAllSystems(ctx)
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module gitea.libretechconsulting.com/rmcguire/edgeos-client
|
module gitea.libretechconsulting.com/rmcguire/toughswitch-client
|
||||||
|
|
||||||
go 1.25.5
|
go 1.25.5
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package edgeos
|
package toughswitch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
Package edgeos provides a client for interacting with Ubiquiti EdgeOS devices
|
Package toughswitch provides a client for interacting with Ubiquiti toughswitch devices
|
||||||
via their REST API. It supports authentication, token management, and
|
via their REST API. It supports authentication, token management, and
|
||||||
retrieval of system, interface, VLAN, and discovery information from
|
retrieval of system, interface, VLAN, and discovery information from
|
||||||
one or more devices.
|
one or more devices.
|
||||||
*/
|
*/
|
||||||
package edgeos
|
package toughswitch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -19,7 +19,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client handles communication with EdgeOS devices.
|
// Client handles communication with toughswitch devices.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
devices map[string]*deviceClient
|
devices map[string]*deviceClient
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package edgeos
|
package toughswitch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -34,11 +34,9 @@ func TestClient_ThreadSafety(t *testing.T) {
|
|||||||
start := make(chan struct{})
|
start := make(chan struct{})
|
||||||
|
|
||||||
// Writer: Adds and deletes hosts
|
// Writer: Adds and deletes hosts
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
<-start
|
<-start
|
||||||
for i := 0; i < 100; i++ {
|
for i := range 100 {
|
||||||
host := fmt.Sprintf("host-%d", i)
|
host := fmt.Sprintf("host-%d", i)
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
Host: host,
|
Host: host,
|
||||||
@@ -54,20 +52,18 @@ func TestClient_ThreadSafety(t *testing.T) {
|
|||||||
t.Logf("Del error: %v", err)
|
t.Logf("Del error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
// Reader: Iterates hosts
|
// Reader: Iterates hosts
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
<-start
|
<-start
|
||||||
for i := 0; i < 10; i++ {
|
for range 10 {
|
||||||
// GetAllInterfaces iterates keys.
|
// GetAllInterfaces iterates keys.
|
||||||
// With mock transport, this will succeed (returning empty structs)
|
// With mock transport, this will succeed (returning empty structs)
|
||||||
// checking for race conditions.
|
// checking for race conditions.
|
||||||
_, _ = client.GetAllInterfaces(ctx)
|
_, _ = client.GetAllInterfaces(ctx)
|
||||||
}
|
}
|
||||||
}()
|
})
|
||||||
|
|
||||||
close(start)
|
close(start)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package edgeos
|
package toughswitch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config represents the configuration for an EdgeOS device.
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Host string
|
Host string
|
||||||
Scheme string
|
Scheme string
|
||||||
@@ -13,6 +12,6 @@ type Config struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
// Transport allows customizing the http transport (useful for testing)
|
// Transport allows customizing the http transport (useful for testing or client middleware)
|
||||||
Transport http.RoundTripper
|
Transport http.RoundTripper
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package edgeos
|
package toughswitch
|
||||||
|
|
||||||
// LoginResponse represents the response from the login endpoint.
|
// LoginResponse represents the response from the login endpoint.
|
||||||
type LoginResponse struct {
|
type LoginResponse struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user