launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/names/service.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package names
     5  
     6  import (
     7  	"regexp"
     8  )
     9  
    10  const (
    11  	ServiceSnippet = "([a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0-9]*)*)"
    12  	NumberSnippet  = "(0|[1-9][0-9]*)"
    13  )
    14  
    15  var validService = regexp.MustCompile("^" + ServiceSnippet + "$")
    16  
    17  // IsService returns whether name is a valid service name.
    18  func IsService(name string) bool {
    19  	return validService.MatchString(name)
    20  }
    21  
    22  // ServiceTag returns the tag for the service with the given name.
    23  func ServiceTag(serviceName string) string {
    24  	return makeTag(ServiceTagKind, serviceName)
    25  }