Introduce Resource/ResourceName/Prefix/Suffix options to RESTClient

RESTClient is an abstraction for simplifying access to resources that
follow the Kubernetes API pattern.  Currently, both Namespace and Path
are coupled, which means changes across versions is complex.  In general,
most access to resources should be to a resource collection (e.g.
"services") with a name (e.g. "foo"). Other constructs, like prefix sections
("watch") or proposed suffix sections ("/pods/foo/spec") only modify this
core pattern.

This commit removes the Path() helper from Request and introduces:

* Prefix(segments ...string) - segments that should go to the beginning of the path.
* Suffix(segments ...string) - segments that should go to the end of the path.
* Resource(string) - collection name, should be after prefix
* Namespace(string) - if specified, should be set after resource but before name
* ResourceName(string) - if specified, should be after namespace

Now, only Prefix and Suffix are order dependent (and with variadics, should be
simpler).  Resource, Namespace, and ResourceName may be specified in any order.

Path() has been removed to prevent downstream consumers of RESTClient from experiencing
behavior change.
Agree


> On Dec 23, 2014, at 6:50 PM, Daniel Smith <notifications@github.com> wrote:
> 
> In pkg/client/request.go:
> 
> > +
> > +// Resource sets the resource to access
> > +func (r *Request) Resource(resource string) *Request {
> > +	if r.err != nil {
> > +		return r
> > +	}
> > +	if len(r.resource) != 0 {
> > +		r.err = fmt.Errorf("resource already set to %q, cannot change to %q", r.resource, resource)
> > +		return r
> > +	}
> > +	r.resource = resource
> > +	return r
> > +}
> > +
> > +// Resource sets the name of a resource to access
> > +func (r *Request) ResourceName(resourceName string) *Request {
> Optional suggestion: I think it'd be OK to just say "Name" here, which would read a bit better. We already have Namespace.
> 
> —
> Reply to this email directly or view it on GitHub.
>