参数检测
# 参数缺失检测
def params_detect(params_lists={}):
for param_name, param_value in params_lists.items():
if not param_value:
return Serializer(status='false', message='Missing parameters [{}]!'.format(param_name), resultCode=10001,
message_zh='参数[{}]缺失!'.format(param_name)).serializer()
# Json参数缺失检测,检查key是否都在
def json_params_detect(json_params_lists={}, must_has=[]):
for key in json_params_lists.keys():
if key in must_has and json_params_lists[key]:
must_has.remove(key)
if must_has:
return Serializer(status='false', message='Missing parameters [{}]!'.format(must_has[0]), resultCode=10001,
message_zh='参数[{}]缺失!'.format(must_has[0])).serializer()
class Serializer():
def __init__(self, resultCode = -1, **kwargs):
self.result = {}
self.result['resultCode'] = resultCode
for k, v in kwargs.items():
self.result[k] = v
def serializer(self):
return self.result