package main import ( "github.com/lxc/lxd/client" ) func main() { // Create a new LXD client c, err := lxd.ConnectLXDUnix("", nil) if err != nil { panic(err) } // Create a new container req := api.ContainersPost{ Name: "my-container", Source: api.ContainerSource{}, } _, err = c.CreateContainer(req) if err != nil { panic(err) } }
package main import ( "fmt" "github.com/lxc/lxd/client" ) func main() { // Create a new LXD client c, err := lxd.ConnectLXDUnix("", nil) if err != nil { panic(err) } // List all containers cts, err := c.ListContainers() if err != nil { panic(err) } for _, ct := range cts { fmt.Printf("Container: %s\n", ct.Name) } }
package main import ( "github.com/lxc/lxd/client" ) func main() { // Create a new LXD client c, err := lxd.ConnectLXDUnix("", nil) if err != nil { panic(err) } // Upload a new image req := api.ImagesPost{ Source: api.ImagesPostSource{ Type: "url", URL: "https://example.com/my-image.tar.gz", }, Public: false, AutoSync: false, } _, err = c.CreateImage(req, nil) if err != nil { panic(err) } }In all three examples, we see the use of functions from the `github.com/lxc/lxd/client` package to connect to and interact with an LXD instance. This package can be considered a library for working with LXD in Go applications.