|
@@ -1,5 +1,9 @@
|
|
|
package setting
|
|
package setting
|
|
|
|
|
|
|
|
|
|
+import (
|
|
|
|
|
+ "reflect"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
type OrgQuota struct {
|
|
type OrgQuota struct {
|
|
|
User int64 `target:"org_user"`
|
|
User int64 `target:"org_user"`
|
|
|
DataSource int64 `target:"data_source"`
|
|
DataSource int64 `target:"data_source"`
|
|
@@ -20,6 +24,38 @@ type GlobalQuota struct {
|
|
|
Session int64 `target:"-"`
|
|
Session int64 `target:"-"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (q *OrgQuota) ToMap() map[string]int64 {
|
|
|
|
|
+ return quotaToMap(*q)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (q *UserQuota) ToMap() map[string]int64 {
|
|
|
|
|
+ return quotaToMap(*q)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (q *GlobalQuota) ToMap() map[string]int64 {
|
|
|
|
|
+ return quotaToMap(*q)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func quotaToMap(q interface{}) map[string]int64 {
|
|
|
|
|
+ qMap := make(map[string]int64)
|
|
|
|
|
+ typ := reflect.TypeOf(q)
|
|
|
|
|
+ val := reflect.ValueOf(q)
|
|
|
|
|
+
|
|
|
|
|
+ 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
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
type QuotaSettings struct {
|
|
type QuotaSettings struct {
|
|
|
Enabled bool
|
|
Enabled bool
|
|
|
Org *OrgQuota
|
|
Org *OrgQuota
|