move toMap function to be a method on the quota structs

This commit is contained in:
woodsaj
2015-09-15 17:18:26 +08:00
parent b7de847236
commit 86ed85aa6e
3 changed files with 38 additions and 26 deletions
-24
View File
@@ -3,7 +3,6 @@ package models
import (
"errors"
"github.com/grafana/grafana/pkg/setting"
"reflect"
"time"
)
@@ -129,26 +128,3 @@ func GetQuotaScopes(target string) ([]QuotaScope, error) {
return scopes, ErrInvalidQuotaTarget
}
}
func QuotaToMap(q interface{}) map[string]int64 {
qMap := make(map[string]int64)
typ := reflect.TypeOf(q)
val := reflect.ValueOf(q)
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
val = val.Elem()
}
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
name := field.Tag.Get("target")
if name == "" {
name = field.Name
}
if name == "-" {
continue
}
value := val.Field(i)
qMap[name] = value.Int()
}
return qMap
}