go-unifi

Installation

Add the go-unifi v2 module, learn its import paths, and verify the install with a tiny program.

go-unifi is a regular Go module. This page adds it to your project and confirms it resolved. To then make your first call, continue to the Quickstart.

Requirements

  • Go 1.26 or later. Check yours with go version.

  • A module to add it to. If you are starting fresh, create one first:

    mkdir myapp && cd myapp
    go mod init example.com/myapp

Add the module

go get github.com/filipowm/go-unifi/v2

The /v2 suffix is part of the path — it is how Go addresses major version 2 of the module. Always include it; omitting it resolves the legacy 1.x line.

Coming from the original paultyng/go-unifi? The import path changed to github.com/filipowm/go-unifi/v2. See Migrating from upstream.

The import paths

The module is split into three packages. Most programs only ever import the first.

unifi

github.com/filipowm/go-unifi/v2/unifi — the client, the configuration, the error sentinels, and every resource type. This is the package you almost always want.

unifi/official

github.com/filipowm/go-unifi/v2/unifi/official — helpers for the Official API surface, such as ListOptions, Page[T], and Collect.

unifi/features

github.com/filipowm/go-unifi/v2/unifi/features — named constants for controller feature flags (e.g. features.ZoneBasedFirewall), used with c.IsFeatureEnabled.

A typical import block looks like this:

import (
	"github.com/filipowm/go-unifi/v2/unifi"
)

Verify the install

Drop this into main.go. It does not touch the network — if it builds and runs, the module and its dependencies resolved correctly.

main.go
package main

import (
	"fmt"

	"github.com/filipowm/go-unifi/v2/unifi"
)

func main() {
	// If this compiles and runs, the module and its dependencies resolved correctly.
	cfg := &unifi.ClientConfig{
		URL:    "https://unifi.example.com",
		APIKey: "your-api-key",
	}
	fmt.Printf("go-unifi is installed. Auth header: %s, target: %s\n", unifi.ApiKeyHeader, cfg.URL)
}

Run it:

go run .

You should see:

go-unifi is installed. Auth header: X-Api-Key, target: https://unifi.example.com

If the build fails on the import path, double-check the /v2 suffix and that your Go is 1.26+.

Next steps

On this page