Simplify ResourceWatcher interface to one function.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user