move toMap function to be a method on the quota structs
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user