Allow clients to determine the difference between create or update on PUT

PUT allows an object to be created (http 201).  This allows REST code to
indicate an object has been created and clients to react to it.

APIServer now deals with <-chan RESTResult instead of <-chan runtime.Object,
allowing more data to be passed through.
This commit is contained in:
Clayton Coleman
2014-10-24 13:16:02 -04:00
parent 2bbd11eda6
commit d5ee171410
25 changed files with 297 additions and 87 deletions

View File

@@ -272,7 +272,7 @@ func (r *Request) Do() Result {
if err != nil {
return Result{err: err}
}
respBody, err := r.c.doRequest(req)
respBody, created, err := r.c.doRequest(req)
if err != nil {
if s, ok := err.(APIStatus); ok {
status := s.Status()
@@ -292,14 +292,16 @@ func (r *Request) Do() Result {
}
}
}
return Result{respBody, err, r.c.Codec}
return Result{respBody, created, err, r.c.Codec}
}
}
// Result contains the result of calling Request.Do().
type Result struct {
body []byte
err error
body []byte
created bool
err error
codec runtime.Codec
}
@@ -324,6 +326,13 @@ func (r Result) Into(obj runtime.Object) error {
return r.codec.DecodeInto(r.body, obj)
}
// WasCreated updates the provided bool pointer to whether the server returned
// 201 created or a different response.
func (r Result) WasCreated(wasCreated *bool) Result {
*wasCreated = r.created
return r
}
// Error returns the error executing the request, nil if no error occurred.
func (r Result) Error() error {
return r.err