diff --git a/codegen/customizations.yml b/codegen/customizations.yml index 2373c02..6d8aaae 100644 --- a/codegen/customizations.yml +++ b/codegen/customizations.yml @@ -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: diff --git a/unifi/client.generated.go b/unifi/client.generated.go index 9263d61..20c2d10 100644 --- a/unifi/client.generated.go +++ b/unifi/client.generated.go @@ -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 diff --git a/unifi/client.go b/unifi/client.go index a8218ce..d63ba7c 100644 --- a/unifi/client.go +++ b/unifi/client.go @@ -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