Просмотр исходного кода

Merge branch 'master' of github.com:kubecost/cost-model into AjayTripathy-fix-n2price

AjayTripathy 6 лет назад
Родитель
Сommit
44d3124b9a
1 измененных файлов с 14 добавлено и 4 удалено
  1. 14 4
      costmodel/router.go

+ 14 - 4
costmodel/router.go

@@ -72,14 +72,24 @@ type DataEnvelope struct {
 	Message string      `json:"message,omitempty"`
 }
 
-// FilterCostData allows through only CostData that matches the given filters for namespace and clusterId
-func FilterCostData(data map[string]*CostData, namespace, clusterId string) map[string]*CostData {
+// FilterFunc is a filter that returns true iff the given CostData should be filtered out
+type FilterFunc func(*CostData) bool
+
+// FilterCostData allows through only CostData that matches all the given filter functions
+func FilterCostData(data map[string]*CostData, filters ...FilterFunc) map[string]*CostData {
 	result := make(map[string]*CostData)
+
+DataLoop:
 	for key, datum := range data {
-		if costDataPassesFilters(datum, namespace, clusterId) {
-			result[key] = datum
+		for _, ff := range filters {
+			if !ff(datum) {
+				// if any filter function check fails, move on to the next datum
+				continue DataLoop
+			}
 		}
+		result[key] = datum
 	}
+
 	return result
 }