初始话项目框架
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import time
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class StandardResponse(BaseModel):
|
||||
"""统一响应格式"""
|
||||
code: int = 200
|
||||
msg: str = "正常响应"
|
||||
data: Any = None
|
||||
timestamp: str = Field(default_factory=lambda: str(int(time.time())))
|
||||
uuid: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
def success(
|
||||
cls,
|
||||
data: Any = None,
|
||||
msg: str = "正常响应",
|
||||
code: int = 200,
|
||||
uuid: str | None = None,
|
||||
) -> "StandardResponse":
|
||||
return cls(code=code, msg=msg, data=data, uuid=uuid)
|
||||
|
||||
@classmethod
|
||||
def fail(
|
||||
cls,
|
||||
msg: str = "操作失败",
|
||||
code: int = 500,
|
||||
data: Any = None,
|
||||
uuid: str | None = None,
|
||||
) -> "StandardResponse":
|
||||
return cls(code=code, msg=msg, data=data, uuid=uuid)
|
||||
Reference in New Issue
Block a user