-
Notifications
You must be signed in to change notification settings - Fork 0
/
limits.go
46 lines (36 loc) · 1010 Bytes
/
limits.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"github.com/jeremyforan/UnifiVoucherGenerator"
"github.com/jeremyforan/UnifiVoucherGenerator/voucher"
"log/slog"
"net/url"
)
func main() {
// URL of the Unifi controller.
baseUrl, err := url.Parse("https://127.0.0.1:8443")
if err != nil {
panic(err)
}
// Create a new client with the username, password, and URL of the Unifi controller.
client := UnifiVoucherGenerator.NewClient("user@email.com", "p455w0rd", baseUrl)
// Login to the Unifi controller.
err = client.Login()
if err != nil {
slog.Info("Failed to login to Unifi controller")
panic(err)
}
// Create a new voucher with default settings.
v := voucher.NewDefaultVoucher()
// Set download to 10Mbps and upload to 2Mbps
v.SetDownloadLimitMbps(10)
v.SetUploadLimitMbps(2)
// Set Bandwidth limit to 100MB
v.SetDataLimitMB(100)
// Add the Voucher to the Unifi controller.
err = client.AddVoucher(v)
if err != nil {
slog.Error("unable to add voucher")
}
fmt.Println(v.AccessCode())
}