feat: add Version method to client to provide system version information (#32)

This commit is contained in:
Mateusz Filipowicz
2025-02-19 09:19:20 +01:00
committed by GitHub
parent d3a3d5a342
commit 16f71e7fe9
3 changed files with 21 additions and 0 deletions

View File

@@ -16,6 +16,10 @@ customizations:
comment: "BaseURL returns the base URL of the controller."
returns:
- "string"
- name: "Version"
comment: "Version returns the version of the UniFi Controller API."
returns:
- "string"
- name: "Do"
comment: "Do sends a request to the controller."
params:

View File

@@ -33,6 +33,9 @@ type Client interface {
// Put sends a PUT request to the controller.
Put(ctx context.Context, apiPath string, reqBody interface{}, respBody interface{}) error
// Version returns the version of the UniFi Controller API.
Version() string
// ==== client methods for APGroup resource ====
// CreateAPGroup creates a resource

View File

@@ -153,6 +153,20 @@ func parseBaseURL(base string) (*url.URL, error) {
return baseURL, nil
}
func (c *client) Version() string {
if c.sysInfo != nil {
return c.sysInfo.Version
}
c.lock.Lock()
defer c.lock.Unlock()
i, err := c.GetSystemInformation()
if err != nil {
return ""
}
c.sysInfo = i
return c.sysInfo.Version
}
func newClientFromConfig(config *ClientConfig, v *validator) (*client, error) {
var rt http.RoundTripper
var err error