Hi Folks,
I’m having a bit of trouble with getting a simple go program to use the canonical LXD module. While I can do a go get command and it seems to work, I am unable to do a go mod tidy.
+ go.mod _______________________________________________________________________________________________________________________________________________________________
[fedora simple]$ go get github.com/canonical/lxd
go: added github.com/canonical/lxd v0.0.0-20230915202554-8185f8a7acc1
[fedora simple]$ go mod tidy
go: finding module for package github.com/canonical/lxd
simple imports
github.com/canonical/lxd: module github.com/canonical/lxd@latest found (v0.0.0-20230915202554-8185f8a7acc1), but does not contain package github.com/canonical/lxd
[fedora simple]$ go run main.go
main.go:5:2: no required module provides package github.com/canonical/lxd; to add it:
go get github.com/canonical/lxd
[fedora simple]$
Here is the code:
package main
import (
"fmt"
"github.com/canonical/lxd"
)
func main() {
client, err := lxd.client.ConnectLxd("", nil)
if err != nil {
fmt.Printf("Error: %s\n", err)
return
}
instances, err := client.GetInstanceNames(api.InstanceTypeContainer)
if err != nil {
fmt.Printf("Error: %s\n", err)
return
}
for _, inst := range instances {
fmt.Printf("Instance Name: %s\n", inst)
}
fmt.Print("Done")
}
I can’t figure out why this error occurs and have been working on it for a couple of days. Is there something simple I’m missing here? Any pointers are much appreciated.
Jason