import "github.com/juju/juju/constraints" // create a new constraints value c := constraints.Value{Attrs: map[string]string{"os": "ubuntu", "arch": "amd64"}} // check if a constraint is satisfied if c.SatisfiedBy(os, arch) { // do something }
import "github.com/juju/juju/constraints" // parse a string constraint c, err := constraints.Parse("mem=4G arch=amd64") // get the value of an attribute mem, ok := c.Attrs["mem"] if !ok { // handle error } // set the value of an attribute c.Attrs["os"] = "ubuntu"This code parses a string constraint specifying that it requires at least 4GB of memory and an architecture of amd64. It also demonstrates how to retrieve and set attribute values of a constraint value.