github.com/cilium/cilium@v1.16.2/pkg/iana/svcname.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package iana 5 6 import ( 7 "regexp" 8 ) 9 10 // IANA Service Name consists of alphanumeric characters of which at 11 // least one is not a number, as well as non-consecutive dashes ('-') 12 // except for in the beginning or the end. 13 // Note: Character case must be ignored when comparing service names. 14 var isSvcName = regexp.MustCompile(`^([a-zA-Z0-9]-?)*[a-zA-Z](-?[a-zA-Z0-9])*$`).MatchString 15 16 // IsSvcName returns true if the string conforms to IANA Service Name specification 17 // (RFC 6335 Section 5.1. Service Name Syntax) 18 func IsSvcName(name string) bool { 19 return len(name) > 0 && len(name) <= 15 && isSvcName(name) 20 }