// NewRoute returns a pointer to a Route given a set of annotations. The annotations are
// assumed to already be processed such that the keys no longer have the Keyspace prefix
// (e.g. romulus/) and the namespace (e.g. ServicePort.Name).
NewRoute returns a pointer to a Route given a set of annotations. The annotations are
assumed to already be processed such that the keys no longer have the Keyspace prefix
and the namespace .
// NewRoute returns a pointer to a Route given a set of annotations . The annotations are // assumed to already be processed such that the keys no longer have the Keyspace prefix // ( e . g . romulus / ) and the namespace ( e . g . ServicePort . Name ) .
func NewRoute(id string, anno annotations) *Route {
	var (
		rt = &Route{parts: make([]*routePart, 0, 1)}
	)
	for key, val := range anno {
		switch key {
		case HeadersKey:
			vals := strings.Fields(strings.Replace(val, ";", "", -1))
			for _, v := range vals {
				bits := strings.SplitN(v, "=", 2)
				if len(bits) < 2 {
					continue
				}
				if er := rt.AddHeader(bits[0], bits[1]); er != nil {
					logger.Warnf("[%v] Failed to add header(%q) matcher: %v", id, bits[0], er)
				}
			}
		case MethodsKey:
			vals := strings.Fields(strings.Replace(val, ";", "", -1))
			for _, v := range vals {
				if er := rt.AddMethod(strings.ToUpper(v)); er != nil {
					logger.Warnf("[%v] Failed to add method matcher: %v", id, er)
				}
			}
		case HostKey:
			if er := rt.AddHost(val); er != nil {
				logger.Warnf("[%v] Failed to add host matcher: %v", id, er)
			}
		case PathKey:
			if er := rt.AddPath(val); er != nil {
				logger.Warnf("[%v] Failed to add patch matcher: %v", id, er)
			}
		case PrefixKey:
			if er := rt.AddPrefix(val); er != nil {
				logger.Warnf("[%v] Failed to app prefix matcher: %v", id, er)
			}
		}
	}
	return rt
}
func NewRoute ( id string , anno annotations ) * Route { var ( rt = & Route { parts : make ( [ ] * routePart , 0 , 1 ) } ) for key , val := range anno { switch key { case HeadersKey : vals := strings . Fields ( strings . Replace ( val , " " , " " , - 1 ) ) for _ , v := range vals { bits := strings . SplitN ( v , " " , 2 ) if len ( bits ) < 2 { continue } if er := rt . AddHeader ( bits [ 0 ] , bits [ 1 ] ) ; er != nil { logger . Warnf ( " " , id , bits [ 0 ] , er ) } } case MethodsKey : vals := strings . Fields ( strings . Replace ( val , " " , " " , - 1 ) ) for _ , v := range vals { if er := rt . AddMethod ( strings . ToUpper ( v ) ) ; er != nil { logger . Warnf ( " " , id , er ) } } case HostKey : if er := rt . AddHost ( val ) ; er != nil { logger . Warnf ( " " , id , er ) } case PathKey : if er := rt . AddPath ( val ) ; er != nil { logger . Warnf ( " " , id , er ) } case PrefixKey : if er := rt . AddPrefix ( val ) ; er != nil { logger . Warnf ( " " , id , er ) } } } return rt }
NewRoute returns a pointer to a Route given a set of annotations.
NewRoute returns a pointer to a Route given a set of annotations .