1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
12
var validUnit = regexp.MustCompile("^" + ServiceSnippet + "/" + NumberSnippet + "$")
14
// UnitTag returns the tag for the unit with the given name.
15
func UnitTag(unitName string) string {
16
return UnitTagPrefix + strings.Replace(unitName, "/", "-", -1)
19
// UnitNameFromTag returns the unit name that was used to create the tag.
20
func UnitNameFromTag(tag string) (string, error) {
21
if !strings.HasPrefix(tag, UnitTagPrefix) {
22
return "", fmt.Errorf("invalid unit tag format: %v", tag)
24
// Strip off the "unit-" prefix.
25
name := tag[len(UnitTagPrefix):]
26
// Put the slashes back.
27
name = strings.Replace(name, "-", "/", -1)
31
// IsUnitName returns whether name is a valid unit name.
32
func IsUnitName(name string) bool {
33
return validUnit.MatchString(name)