// NewResource returns a Resource pointer given an id, annotations and an annotations namespace which
// should be ServicePort.Name
NewResource returns a Resource pointer given an id, annotations and an annotations namespace which
should be ServicePort.Name
// NewResource returns a Resource pointer given an id annotations and an annotations namespace which // should be ServicePort . Name
func NewResource(id, namespace string, anno annotations) *Resource {
	var (
		an annotations = make(map[string]string)
	)
	for key, value := range anno {
		if strings.HasPrefix(key, Keyspace) {
			bits := strings.SplitN(path.Base(key), ".", 2)
			if len(bits) == 2 && namespace == "" && bits[0] != "middleware" {
				continue
			}
			switch len(bits) {
			case 2:
				if bits[0] == namespace {
					an[bits[1]] = value
				} else if bits[0] == "middleware" {
					an[strings.Join(bits, ".")] = value
				}
			case 1:
				if _, ok := an[bits[0]]; !ok {
					an[bits[0]] = value
				}
			}
		}
	}
	websocket := false
	if val, ok := an["websocket"]; ok {
		if b, er := strconv.ParseBool(val); er == nil {
			websocket = b
		}
	}
	return &Resource{
		id:          id,
		Route:       NewRoute(id, an),
		annotations: an,
		servers:     make([]*Server, 0, 1),
		websocket:   websocket,
	}
}
func NewResource ( id , namespace string , anno annotations ) * Resource { var ( an annotations = make ( map [ string ] string ) ) for key , value := range anno { if strings . HasPrefix ( key , Keyspace ) { bits := strings . SplitN ( path . Base ( key ) , " " , 2 ) if len ( bits ) == 2 && namespace == " " && bits [ 0 ] != " " { continue } switch len ( bits ) { case 2 : if bits [ 0 ] == namespace { an [ bits [ 1 ] ] = value } else if bits [ 0 ] == " " { an [ strings . Join ( bits , " " ) ] = value } case 1 : if _ , ok := an [ bits [ 0 ] ] ; ! ok { an [ bits [ 0 ] ] = value } } } } websocket := false if val , ok := an [ " " ] ; ok { if b , er := strconv . ParseBool ( val ) ; er == nil { websocket = b } } return & Resource { id : id , Route : NewRoute ( id , an ) , annotations : an , servers : make ( [ ] * Server , 0 , 1 ) , websocket : websocket , } }
NewResource returns a Resource pointer given an id, annotations and an annotations namespace which
should be ServicePort.Name
NewResource returns a Resource pointer given an id annotations and an annotations namespace which should be ServicePort . Name