mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-23 23:44:12 +08:00
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
// Copyright 2019 Yunion
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package quotas
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type SOutOfQuotaError struct {
|
|
name string
|
|
limit int
|
|
used int
|
|
}
|
|
|
|
type SOutOfQuotaErrors struct {
|
|
errors []SOutOfQuotaError
|
|
}
|
|
|
|
func (e *SOutOfQuotaError) Error() string {
|
|
return fmt.Sprintf("%s limit %d used %d", e.name, e.limit, e.used)
|
|
}
|
|
|
|
func (es *SOutOfQuotaErrors) Error() string {
|
|
qs := make([]string, len(es.errors))
|
|
for i := range es.errors {
|
|
e := es.errors[i]
|
|
qs[i] = e.Error()
|
|
}
|
|
return fmt.Sprintf("Out of quota: %s", strings.Join(qs, ", "))
|
|
}
|
|
|
|
func (es *SOutOfQuotaErrors) IsError() bool {
|
|
if len(es.errors) == 0 {
|
|
return false
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
|
|
func NewOutOfQuotaError() *SOutOfQuotaErrors {
|
|
return &SOutOfQuotaErrors{
|
|
errors: make([]SOutOfQuotaError, 0),
|
|
}
|
|
}
|
|
|
|
func (es *SOutOfQuotaErrors) Add(name string, limit int, used int) {
|
|
e := SOutOfQuotaError{
|
|
name: name,
|
|
limit: limit,
|
|
used: used,
|
|
}
|
|
es.errors = append(es.errors, e)
|
|
}
|