1 package reverseproxy 2 3 import "strings" 4 5 // MatchServiceName allows differing ways of matching a service name to a service. 6 type MatchServiceName interface { 7 MatchService(string) bool 8 } 9 10 // HostName represents an exact hostname to match on. 11 type HostName string 12 13 // MatchService implements the MatchServiceName interface. 14 func (h HostName) MatchService(serviceName string) bool { 15 return string(h) == serviceName 16 } 17 18 // HostNameSuffix represents a partial hostname to match the end on. 19 type HostNameSuffix string 20 21 // MatchService implements the MatchServiceName interface. 22 func (h HostNameSuffix) MatchService(serviceName string) bool { 23 return strings.HasSuffix(serviceName, string(h)) 24 } 25 26 // Hosts represents a list of service names to match against. 27 type Hosts []MatchServiceName 28 29 // MatchService implements the MatchServiceName interface. 30 func (h Hosts) MatchService(serviceName string) bool { 31 for _, s := range h { 32 if s.MatchService(serviceName) { 33 return true 34 } 35 } 36 37 return false 38 } 39