项目初始化
This commit is contained in:
32
core/response.py
Normal file
32
core/response.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# 依赖安装:pip install orjson
|
||||
from fastapi.responses import ORJSONResponse as Response
|
||||
from fastapi import status as http_status
|
||||
from core import status as http
|
||||
|
||||
|
||||
class SuccessResponse(Response):
|
||||
"""
|
||||
成功响应
|
||||
"""
|
||||
def __init__(self, data=None, msg="success", code=http.HTTP_SUCCESS, status=http_status.HTTP_200_OK, **kwargs):
|
||||
self.data = {
|
||||
"code": code,
|
||||
"message": msg,
|
||||
"data": data
|
||||
}
|
||||
self.data.update(kwargs)
|
||||
super().__init__(content=self.data, status_code=status)
|
||||
|
||||
|
||||
class ErrorResponse(Response):
|
||||
"""
|
||||
失败响应
|
||||
"""
|
||||
def __init__(self, msg=None, code=http.HTTP_ERROR, status=http_status.HTTP_200_OK, **kwargs):
|
||||
self.data = {
|
||||
"code": code,
|
||||
"message": msg,
|
||||
"data": []
|
||||
}
|
||||
self.data.update(kwargs)
|
||||
super().__init__(content=self.data, status_code=status)
|
14
core/status.py
Normal file
14
core/status.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @version : 1.0
|
||||
# @Create Time : 2022/8/10 22:20
|
||||
# @File : status.py
|
||||
# @IDE : PyCharm
|
||||
# @desc : 简要说明
|
||||
|
||||
|
||||
HTTP_SUCCESS = 200
|
||||
HTTP_ERROR = 400
|
||||
HTTP_401_UNAUTHORIZED = 401
|
||||
HTTP_403_FORBIDDEN = 403
|
||||
HTTP_404_NOT_FOUND = 404
|
Reference in New Issue
Block a user