[WIP] API refactor (#1737)

* refactor openpitrix API

Signed-off-by: hongming <talonwan@yunify.com>

* add openpitrix mock client

Signed-off-by: hongming <talonwan@yunify.com>

* refactor tenant API

Signed-off-by: hongming <talonwan@yunify.com>

* refactor IAM API

Signed-off-by: hongming <talonwan@yunify.com>

* refactor IAM API

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2020-01-13 13:36:21 +08:00
committed by zryfish
parent c40d1542a2
commit 71849f028f
66 changed files with 5415 additions and 4366 deletions

View File

@@ -30,11 +30,10 @@ const (
OrderByParam = "orderBy"
ConditionsParam = "conditions"
ReverseParam = "reverse"
NameParam = "name"
)
func ParsePaging(paging string) (limit, offset int) {
func ParsePaging(req *restful.Request) (limit, offset int) {
paging := req.QueryParameter(PagingParam)
limit = 10
offset = 0
if groups := regexp.MustCompile(`^limit=(-?\d+),page=(\d+)$`).FindStringSubmatch(paging); len(groups) == 3 {
@@ -45,7 +44,9 @@ func ParsePaging(paging string) (limit, offset int) {
return
}
func ParseConditions(conditionsStr string) (*Conditions, error) {
func ParseConditions(req *restful.Request) (*Conditions, error) {
conditionsStr := req.QueryParameter(ConditionsParam)
conditions := &Conditions{Match: make(map[string]string, 0), Fuzzy: make(map[string]string, 0)}
@@ -76,20 +77,19 @@ func ParseConditions(conditionsStr string) (*Conditions, error) {
return conditions, nil
}
func ParseReverse(req *restful.Request) bool {
reverse := req.QueryParameter(ReverseParam)
b, err := strconv.ParseBool(reverse)
if err != nil {
return false
}
return b
}
type Conditions struct {
Match map[string]string
Fuzzy map[string]string
}
func GetBoolValueWithDefault(req *restful.Request, name string, dv bool) bool {
reverse := req.QueryParameter(name)
if v, err := strconv.ParseBool(reverse); err == nil {
return v
}
return dv
}
func GetStringValueWithDefault(req *restful.Request, name string, dv string) string {
v := req.QueryParameter(name)
if v == "" {