Rewrite the function 'validatePrivileges' without checking order

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
Upstream-commit: dafeeac4fd0ba811a4d88fe9ee335992680c8ad3
Component: engine
This commit is contained in:
Yanqiang Miao
2017-02-04 08:47:40 +08:00
parent 8cc16f0566
commit 9bd3ca6b09
3 changed files with 98 additions and 2 deletions
@@ -3,6 +3,7 @@ package types
import (
"encoding/json"
"fmt"
"sort"
)
// PluginsListResponse contains the response for the Engine API
@@ -62,3 +63,17 @@ type PluginPrivilege struct {
// PluginPrivileges is a list of PluginPrivilege
type PluginPrivileges []PluginPrivilege
func (s PluginPrivileges) Len() int {
return len(s)
}
func (s PluginPrivileges) Less(i, j int) bool {
return s[i].Name < s[j].Name
}
func (s PluginPrivileges) Swap(i, j int) {
sort.Strings(s[i].Value)
sort.Strings(s[j].Value)
s[i], s[j] = s[j], s[i]
}