Simplify ResourceWatcher interface to one function.

This commit is contained in:
Daniel Smith
2014-08-06 14:55:37 -07:00
parent 71709ae09e
commit 49cded3800
7 changed files with 34 additions and 79 deletions

View File

@@ -33,8 +33,7 @@ type WatchHandler struct {
storage map[string]RESTStorage
}
func (s *APIServer) getWatchParams(query url.Values) (id string, label, field labels.Selector, resourceVersion uint64) {
id = query.Get("id")
func getWatchParams(query url.Values) (label, field labels.Selector, resourceVersion uint64) {
if s, err := labels.ParseSelector(query.Get("labels")); err != nil {
label = labels.Everything()
} else {
@@ -48,7 +47,7 @@ func (s *APIServer) getWatchParams(query url.Values) (id string, label, field la
if rv, err := strconv.ParseUint(query.Get("resourceVersion"), 10, 64); err == nil {
resourceVersion = rv
}
return id, label, field, resourceVersion
return label, field, resourceVersion
}
// handleWatch processes a watch request
@@ -62,14 +61,8 @@ func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
notFound(w, req)
}
if watcher, ok := storage.(ResourceWatcher); ok {
var watching watch.Interface
var err error
id, label, field, resourceVersion := s.getWatchParams(req.URL.Query())
if id != "" {
watching, err = watcher.WatchSingle(id, resourceVersion)
} else {
watching, err = watcher.WatchAll(label, field, resourceVersion)
}
label, field, resourceVersion := getWatchParams(req.URL.Query())
watching, err := watcher.Watch(label, field, resourceVersion)
if err != nil {
internalError(err, w)
return