public_sentiment/web/dto/api_result.py
2024-09-18 13:41:28 +08:00

34 lines
837 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
class ApiResult:
"""
接口返回类
"""
def __init__(self):
super().__init__()
def __init__(self, success, code, data, message):
# 只要服务端没报错success都是True
self.success = success
# 根据处理结果不同,返回不同的值
self.code = code
# 返回数据
self.data = data
# 提示信息
self.message = message
@staticmethod
def instance(success, code, data, message):
return ApiResult(success, code, data, message).__dict__
@staticmethod
def ok(code, data, message):
return ApiResult(True, code, data, message).__dict__
@staticmethod
def fail(code, data, message):
return ApiResult(False, code, data, message).__dict__