tag, err := names.ParseUnitTag("mysql/0") if err != nil { log.Fatalf("Error parsing unit tag: %v", err) }
tag := names.NewUnitTag("mongodb/1") if !tag.IsValid() { log.Fatalf("Invalid unit tag: %s", tag.Value()) }In this example, the NewUnitTag function is used to create a new UnitTag struct from the string "mongodb/1". The IsValid function is then called to check if the UnitTag is valid. If it is not valid, the program will log an error message containing the Value of the UnitTag. Overall, the examples show how the names library can be used to parse and validate Juju object names such as UnitTags.