sanic-api 0.2.9__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. sanic_api-0.3.0/.gitignore +147 -0
  2. sanic_api-0.3.0/.pre-commit-config.yaml +18 -0
  3. sanic_api-0.3.0/CHANGELOG.md +98 -0
  4. sanic_api-0.3.0/COMMIT_GUIDE.MD +10 -0
  5. sanic_api-0.3.0/PKG-INFO +160 -0
  6. sanic_api-0.3.0/README.md +124 -0
  7. sanic_api-0.3.0/example/app.py +62 -0
  8. sanic_api-0.3.0/example/log.txt +1584 -0
  9. sanic_api-0.3.0/example/mini_app.py +11 -0
  10. sanic_api-0.3.0/images/logo.png +0 -0
  11. sanic_api-0.3.0/pyproject.toml +154 -0
  12. sanic_api-0.3.0/requirements-dev.lock +142 -0
  13. sanic_api-0.3.0/requirements.lock +81 -0
  14. sanic_api-0.3.0/src/sanic_api/__init__.py +3 -0
  15. sanic_api-0.3.0/src/sanic_api/api/__init__.py +17 -0
  16. sanic_api-0.3.0/src/sanic_api/api/model.py +0 -0
  17. sanic_api-0.3.0/src/sanic_api/api/request.py +157 -0
  18. sanic_api-0.3.0/src/sanic_api/api/response.py +34 -0
  19. sanic_api-0.3.0/src/sanic_api/app.py +306 -0
  20. sanic_api-0.3.0/src/sanic_api/config/__init__.py +1 -0
  21. sanic_api-0.3.0/src/sanic_api/config/setting.py +85 -0
  22. sanic_api-0.3.0/src/sanic_api/logger/__init__.py +0 -0
  23. sanic_api-0.3.0/src/sanic_api/logger/config.py +99 -0
  24. sanic_api-0.3.0/src/sanic_api/logger/extension.py +130 -0
  25. sanic_api-0.3.0/src/sanic_api/openapi/__init__.py +0 -0
  26. sanic_api-0.3.0/src/sanic_api/openapi/extension.py +0 -0
  27. sanic_api-0.3.0/src/sanic_api/utils/__init__.py +0 -0
  28. {sanic-api-0.2.9/sanic_api → sanic_api-0.3.0/src/sanic_api/utils}/enum.py +1 -31
  29. sanic-api-0.2.9/PKG-INFO +0 -89
  30. sanic-api-0.2.9/README.MD +0 -79
  31. sanic-api-0.2.9/example/__main__.py +0 -19
  32. sanic-api-0.2.9/example/api/__init__.py +0 -1
  33. sanic-api-0.2.9/example/api/t1/__init__.py +0 -2
  34. sanic-api-0.2.9/example/api/t1/t1_1.py +0 -22
  35. sanic-api-0.2.9/example/api/t1/t1_2.py +0 -9
  36. sanic-api-0.2.9/example/api/t2/__init__.py +0 -1
  37. sanic-api-0.2.9/example/api/t2/t2.py +0 -9
  38. sanic-api-0.2.9/example/api/t2/t3/__init__.py +0 -1
  39. sanic-api-0.2.9/example/api/t2/t3/t3.py +0 -9
  40. sanic-api-0.2.9/example/api/user.py +0 -89
  41. sanic-api-0.2.9/example/api/validator.py +0 -97
  42. sanic-api-0.2.9/example/app.py +0 -62
  43. sanic-api-0.2.9/example/settings.py +0 -10
  44. sanic-api-0.2.9/pyproject.toml +0 -94
  45. sanic-api-0.2.9/sanic_api/__init__.py +0 -21
  46. sanic-api-0.2.9/sanic_api/api/__init__.py +0 -2
  47. sanic-api-0.2.9/sanic_api/api/api.py +0 -177
  48. sanic-api-0.2.9/sanic_api/api/exception.py +0 -46
  49. sanic-api-0.2.9/sanic_api/api/extend.py +0 -25
  50. sanic-api-0.2.9/sanic_api/api/handle_exception.py +0 -61
  51. sanic-api-0.2.9/sanic_api/api/model.py +0 -46
  52. sanic-api-0.2.9/sanic_api/api/validators.py +0 -76
  53. sanic-api-0.2.9/sanic_api/config/__init__.py +0 -1
  54. sanic-api-0.2.9/sanic_api/config/sanic.py +0 -19
  55. sanic-api-0.2.9/sanic_api/config/sanic_api.py +0 -11
  56. sanic-api-0.2.9/sanic_api/config/setting.py +0 -30
  57. sanic-api-0.2.9/sanic_api/logger/__init__.py +0 -1
  58. sanic-api-0.2.9/sanic_api/logger/config.py +0 -77
  59. sanic-api-0.2.9/sanic_api/logger/extend.py +0 -71
  60. sanic-api-0.2.9/sanic_api/logger/sanic_http.py +0 -68
  61. sanic-api-0.2.9/sanic_api/openapi/__init__.py +0 -7
  62. sanic-api-0.2.9/sanic_api/openapi/openapi.py +0 -102
  63. sanic-api-0.2.9/sanic_api/utils.py +0 -112
  64. {sanic-api-0.2.9 → sanic_api-0.3.0}/LICENSE.txt +0 -0
  65. {sanic-api-0.2.9 → sanic_api-0.3.0}/example/__init__.py +0 -0
@@ -0,0 +1,147 @@
1
+ # ---> Python
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # pycharm
11
+ .idea/
12
+
13
+ .DS_Store
14
+
15
+ # rye
16
+ .python-version
17
+
18
+ # Distribution / packaging
19
+ .Python
20
+ build/
21
+ develop-eggs/
22
+ dist/
23
+ downloads/
24
+ eggs/
25
+ .eggs/
26
+ lib/
27
+ lib64/
28
+ parts/
29
+ sdist/
30
+ var/
31
+ wheels/
32
+ share/python-wheels/
33
+ *.egg-info/
34
+ .installed.cfg
35
+ *.egg
36
+ MANIFEST
37
+
38
+ # PyInstaller
39
+ # Usually these files are written by a python script from a template
40
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
41
+ *.manifest
42
+ *.spec
43
+
44
+ # Installer logs
45
+ pip-log.txt
46
+ pip-delete-this-directory.txt
47
+
48
+ # Unit test / coverage reports
49
+ htmlcov/
50
+ .tox/
51
+ .nox/
52
+ .coverage
53
+ .coverage.*
54
+ .cache
55
+ nosetests.xml
56
+ coverage.xml
57
+ *.cover
58
+ *.py,cover
59
+ .hypothesis/
60
+ .pytest_cache/
61
+ cover/
62
+
63
+ # Translations
64
+ *.mo
65
+ *.pot
66
+
67
+ # Django stuff:
68
+ *.log
69
+ local_settings.py
70
+ db.sqlite3
71
+ db.sqlite3-journal
72
+
73
+ # Flask stuff:
74
+ instance/
75
+ .webassets-cache
76
+
77
+ # Scrapy stuff:
78
+ .scrapy
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # PyBuilder
84
+ .pybuilder/
85
+ target/
86
+
87
+ # Jupyter Notebook
88
+ .ipynb_checkpoints
89
+
90
+ # IPython
91
+ profile_default/
92
+ ipython_config.py
93
+
94
+ # pyenv
95
+ # For a library or package, you might want to ignore these files since the code is
96
+ # intended to run in multiple environments; otherwise, check them in:
97
+ # .python-version
98
+
99
+ # pipenv
100
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
101
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
102
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
103
+ # install all needed dependencies.
104
+ #Pipfile.lock
105
+
106
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
107
+ __pypackages__/
108
+
109
+ # Celery stuff
110
+ celerybeat-schedule
111
+ celerybeat.pid
112
+
113
+ # SageMath parsed files
114
+ *.sage.py
115
+
116
+ # Environments
117
+ .env
118
+ .venv
119
+ env/
120
+ venv/
121
+ ENV/
122
+ env.bak/
123
+ venv.bak/
124
+
125
+ # Spyder project settings
126
+ .spyderproject
127
+ .spyproject
128
+
129
+ # Rope project settings
130
+ .ropeproject
131
+
132
+ # mkdocs documentation
133
+ /site
134
+
135
+ # mypy
136
+ .mypy_cache/
137
+ .dmypy.json
138
+ dmypy.json
139
+
140
+ # Pyre type checker
141
+ .pyre/
142
+
143
+ # pytype static type analyzer
144
+ .pytype/
145
+
146
+ # Cython debug symbols
147
+ cython_debug/
@@ -0,0 +1,18 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ # bandit
5
+ - repo: https://github.com/PyCQA/bandit
6
+ rev: 1.7.10
7
+ hooks:
8
+ - id: bandit
9
+ args: [ "-c", "pyproject.toml" ]
10
+ additional_dependencies: [ "bandit[toml]" ]
11
+
12
+ # ruff
13
+ - repo: https://github.com/astral-sh/ruff-pre-commit
14
+ rev: 'v0.6.9'
15
+ hooks:
16
+ - id: ruff
17
+ args: [ --fix, --exit-non-zero-on-fix, --show-fixes ]
18
+ - id: ruff-format
@@ -0,0 +1,98 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+
9
+ ## [0.2.6] - 2023-07-05
10
+
11
+ ### Fixed
12
+
13
+ - 修复配置类报错的问题
14
+
15
+ ### Changed
16
+
17
+ - 升级sanic依赖版本为22.3
18
+ - 增加`setuptools`依赖
19
+
20
+ ## [0.2.5] - 2023-04-09
21
+
22
+ ### Added
23
+
24
+ - 支持捕获在中间件期间发生错误的异常情况
25
+ - 增加配置类功能
26
+ - 示例文件更新
27
+ - 工具方法中新增自动蓝图方法
28
+
29
+ ### Changed
30
+
31
+ - 默认的json dumps方法改为orjson
32
+ - sanic 最低版本依赖更新至22.12
33
+ - 优化API响应封装及响应文档的生成
34
+
35
+ ### Fixed
36
+
37
+ - 修复openapi tag重复的问题
38
+ - 修复日志级别判断不准问题
39
+
40
+ ## [0.2.4] - 2023-02-05
41
+
42
+ ### Fixed
43
+
44
+ - 修复示例文件不生效的问题
45
+
46
+ ## [0.2.3] - 2023-02-03
47
+
48
+ ### Fixed
49
+
50
+ - 修复无蓝图的api接口blueprint.ctx.desc报错的问题
51
+ - 实现_missing_方法,修复枚举基类无法识别枚举值的问题
52
+
53
+ ### Changed
54
+
55
+ - 请求接口无参数时访问日志中不打印 “args:”
56
+ - 枚举基类字段类名称修改,避免重名
57
+
58
+ ### Added
59
+
60
+ - API接口类支持自定义接口标签和接口描述
61
+ - 添加types-ujson包
62
+ - 自动生成的文档支持识别必须和可选参数
63
+ - 枚举基类增加to_desc方法列出枚举的所有描述
64
+
65
+ ## [0.2.0] - 2023-01-19
66
+
67
+ ### Changed
68
+
69
+ - api json序列化改为使用ujson
70
+ - 移除部分3.10以上的语法
71
+
72
+ ### Added
73
+
74
+ - 日志功能优化改进:
75
+ - 实现方式更加简洁优雅
76
+ - 可按照类型去区分
77
+ - 日志增加打印请求ID
78
+ - json响应体格式设置为可配置的
79
+ - 添加ujson包,移除orjson包
80
+ - 读取蓝图上面的 blueprint.ctx.desc 属性来代替name设置中文tag名
81
+ - 引入mypy、autoflake等代码检查工具
82
+ - 添加配置文件基类
83
+
84
+ ## [0.1.1] - 2022-12-19
85
+
86
+ ### Changed
87
+
88
+ - pip 首页的文件修改
89
+
90
+ ## [0.1.0] - 2022-12-19
91
+
92
+ ### Added
93
+
94
+ - 接口参数校验
95
+ - 接口文档生成
96
+ - 日志使用`loguru`代替
97
+ - 接口异常拦截
98
+ - 接口响应统一化
@@ -0,0 +1,10 @@
1
+ - ✨ feat: 一个新特性
2
+ - ➕ improvement: 对现有特性的提升
3
+ - 🐛 fix: 修复Bug
4
+ - 🛠 refactor: 代码重构,注意和特性、重构区分开
5
+ - 📚 docs: 变更文档
6
+ - 💅 style: 修改格式,不影响功能,例如空格、代码格式等
7
+ - 📈 perf: 性能提升
8
+ - 🔧 ci: 修改ci相关配置、脚本等
9
+ - ⏪ revert: 回退版本
10
+ - 🗯 chore: 杂务,不属于以上类型,例如run build、引入或更新软件包等
@@ -0,0 +1,160 @@
1
+ Metadata-Version: 2.4
2
+ Name: sanic-api
3
+ Version: 0.3.0
4
+ Summary: Sanic 框架实用API工具集,拥有自动生成文档、参数校验、配置的导入、日志功能的优化等功能,更好的助力接口的开发
5
+ Project-URL: homepage, https://github.com/x-haose/sanic-api
6
+ Project-URL: repository, https://github.com/x-haose/sanic-api
7
+ Project-URL: documentation, https://github.com/x-haose/sanic-api
8
+ Author-email: 昊色居士 <xhrtxh@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE.txt
11
+ Keywords: Sanic,Sanic扩展,异步
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: POSIX :: BSD
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Internet :: WWW/HTTP
23
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: hs-config==0.1.3
27
+ Requires-Dist: loguru>=0.7.2
28
+ Requires-Dist: loki-logger-handler>=0.1.4
29
+ Requires-Dist: orjson>=3.8.6
30
+ Requires-Dist: requests>=2.32.0
31
+ Requires-Dist: sanic-ext>=23.12.0
32
+ Requires-Dist: sanic>=24.12.0
33
+ Requires-Dist: sentry-sdk>=2.17.0
34
+ Requires-Dist: ujson>=5.7.0
35
+ Description-Content-Type: text/markdown
36
+
37
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
38
+ [![Python](https://img.shields.io/badge/Python-3.10+-yellow.svg?logo=python)]()
39
+ [![Sanic](https://img.shields.io/badge/framework-Sanic-Server.svg)](http://www.gnu.org/licenses/agpl-3.0)
40
+
41
+ # Sanic-API
42
+
43
+ 让您的sanic服务程序更好的支持API文档、参数校验、日志打印、响应规范等
44
+
45
+ ## 特性
46
+
47
+ - 无需任何多余改动,全自动生成openapi文档,使用更加方便 (新版方案正在积极优化开发中)
48
+
49
+ - 基于`pydantic`的参数校验器,让接口的请求及响应更符合你的预期,使用更方便
50
+
51
+ - 使用`loguru`库代替官方`logging`日志库,并对访问日志进行扩展,支持写入文件及推送loki
52
+
53
+ - 使用了基于`pydantic-settings`的项目配置方案,支持json、yml、ini、.env等多种格式
54
+
55
+ - 对sanic的启动进行了简单的封装,可快速启动项目
56
+
57
+
58
+ ## 截图
59
+
60
+ ## 路线图
61
+
62
+ - 全自动生成openapi文档
63
+
64
+ - 编写详细文档
65
+
66
+ ## 安装
67
+
68
+ 使用 pip 安装 sanic-api
69
+
70
+ ```bash
71
+ pip install sanic-api
72
+ ```
73
+
74
+ ## 使用方法/示例
75
+
76
+ ### 最小示例
77
+ ```python
78
+ from sanic_api.app import BaseApp
79
+
80
+
81
+ class App(BaseApp):
82
+ """
83
+ 最小的sanic服务示例
84
+ """
85
+
86
+
87
+ if __name__ == "__main__":
88
+ App.run()
89
+ ```
90
+
91
+ ### 带参数校验的示例
92
+ ```python
93
+ from pydantic import BaseModel, Field
94
+ from sanic import Blueprint, Sanic, json
95
+ from sanic.log import logger
96
+
97
+ from sanic_api.api import BaseRespTml, Request
98
+ from sanic_api.app import BaseApp
99
+
100
+ user_blueprint = Blueprint("user", "/user")
101
+
102
+
103
+ class UserInfoModel(BaseModel):
104
+ user_id: int = Field(title="用户ID")
105
+
106
+
107
+ class UserInfoResponse(BaseRespTml):
108
+ user_name: str = Field(title="用户名")
109
+
110
+
111
+ class UseLoginRequest(Request):
112
+ form_data: UserInfoModel
113
+
114
+
115
+ @user_blueprint.post("info")
116
+ async def user_info(request: Request, json_data: UserInfoModel):
117
+ """
118
+ 获取用户信息
119
+ """
120
+ logger.info(f"data: {json_data}")
121
+ info = UserInfoResponse(user_name="张三")
122
+ info.temp_data.code = "0000"
123
+ info.temp_data.msg = "查询成功"
124
+ return info.resp()
125
+
126
+
127
+ @user_blueprint.post("login")
128
+ async def user_login(request: UseLoginRequest):
129
+ """
130
+ 用户登录
131
+ """
132
+ logger.info(f"user_id: {request.form_data.user_id}")
133
+ return json(request.form_data.model_dump())
134
+
135
+
136
+ class App(BaseApp):
137
+ """
138
+ 服务示例
139
+ """
140
+
141
+ async def setup_route(self, app: Sanic):
142
+ api = Blueprint.group(url_prefix="api")
143
+ api.append(user_blueprint)
144
+ app.blueprint(api)
145
+
146
+
147
+ if __name__ == "__main__":
148
+ App.run()
149
+ ```
150
+
151
+ ## 开发
152
+
153
+ 要部署这个项目,请先安装rye
154
+
155
+ ```bash
156
+ rye sync
157
+ ```
158
+
159
+ ## 文档
160
+ 正在编写中,敬请期待
@@ -0,0 +1,124 @@
1
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
2
+ [![Python](https://img.shields.io/badge/Python-3.10+-yellow.svg?logo=python)]()
3
+ [![Sanic](https://img.shields.io/badge/framework-Sanic-Server.svg)](http://www.gnu.org/licenses/agpl-3.0)
4
+
5
+ # Sanic-API
6
+
7
+ 让您的sanic服务程序更好的支持API文档、参数校验、日志打印、响应规范等
8
+
9
+ ## 特性
10
+
11
+ - 无需任何多余改动,全自动生成openapi文档,使用更加方便 (新版方案正在积极优化开发中)
12
+
13
+ - 基于`pydantic`的参数校验器,让接口的请求及响应更符合你的预期,使用更方便
14
+
15
+ - 使用`loguru`库代替官方`logging`日志库,并对访问日志进行扩展,支持写入文件及推送loki
16
+
17
+ - 使用了基于`pydantic-settings`的项目配置方案,支持json、yml、ini、.env等多种格式
18
+
19
+ - 对sanic的启动进行了简单的封装,可快速启动项目
20
+
21
+
22
+ ## 截图
23
+
24
+ ## 路线图
25
+
26
+ - 全自动生成openapi文档
27
+
28
+ - 编写详细文档
29
+
30
+ ## 安装
31
+
32
+ 使用 pip 安装 sanic-api
33
+
34
+ ```bash
35
+ pip install sanic-api
36
+ ```
37
+
38
+ ## 使用方法/示例
39
+
40
+ ### 最小示例
41
+ ```python
42
+ from sanic_api.app import BaseApp
43
+
44
+
45
+ class App(BaseApp):
46
+ """
47
+ 最小的sanic服务示例
48
+ """
49
+
50
+
51
+ if __name__ == "__main__":
52
+ App.run()
53
+ ```
54
+
55
+ ### 带参数校验的示例
56
+ ```python
57
+ from pydantic import BaseModel, Field
58
+ from sanic import Blueprint, Sanic, json
59
+ from sanic.log import logger
60
+
61
+ from sanic_api.api import BaseRespTml, Request
62
+ from sanic_api.app import BaseApp
63
+
64
+ user_blueprint = Blueprint("user", "/user")
65
+
66
+
67
+ class UserInfoModel(BaseModel):
68
+ user_id: int = Field(title="用户ID")
69
+
70
+
71
+ class UserInfoResponse(BaseRespTml):
72
+ user_name: str = Field(title="用户名")
73
+
74
+
75
+ class UseLoginRequest(Request):
76
+ form_data: UserInfoModel
77
+
78
+
79
+ @user_blueprint.post("info")
80
+ async def user_info(request: Request, json_data: UserInfoModel):
81
+ """
82
+ 获取用户信息
83
+ """
84
+ logger.info(f"data: {json_data}")
85
+ info = UserInfoResponse(user_name="张三")
86
+ info.temp_data.code = "0000"
87
+ info.temp_data.msg = "查询成功"
88
+ return info.resp()
89
+
90
+
91
+ @user_blueprint.post("login")
92
+ async def user_login(request: UseLoginRequest):
93
+ """
94
+ 用户登录
95
+ """
96
+ logger.info(f"user_id: {request.form_data.user_id}")
97
+ return json(request.form_data.model_dump())
98
+
99
+
100
+ class App(BaseApp):
101
+ """
102
+ 服务示例
103
+ """
104
+
105
+ async def setup_route(self, app: Sanic):
106
+ api = Blueprint.group(url_prefix="api")
107
+ api.append(user_blueprint)
108
+ app.blueprint(api)
109
+
110
+
111
+ if __name__ == "__main__":
112
+ App.run()
113
+ ```
114
+
115
+ ## 开发
116
+
117
+ 要部署这个项目,请先安装rye
118
+
119
+ ```bash
120
+ rye sync
121
+ ```
122
+
123
+ ## 文档
124
+ 正在编写中,敬请期待
@@ -0,0 +1,62 @@
1
+ from pydantic import BaseModel, Field
2
+ from sanic import Blueprint, Sanic, json
3
+ from sanic.log import logger
4
+
5
+ from sanic_api.api import BaseRespTml, Request
6
+ from sanic_api.app import BaseApp
7
+
8
+ user_blueprint = Blueprint("user", "/user")
9
+
10
+
11
+ class UserInfoModel(BaseModel):
12
+ user_id: int = Field(title="用户ID")
13
+
14
+
15
+ class UserInfoResponse(BaseRespTml):
16
+ user_name: str = Field(title="用户名")
17
+
18
+
19
+ class UseLoginRequest(Request):
20
+ """
21
+ 用户登录
22
+ 用户登录描述
23
+ 这也是描述
24
+ """
25
+
26
+ form_data: UserInfoModel
27
+
28
+
29
+ @user_blueprint.post("info")
30
+ async def user_info(request: Request, json_data: UserInfoModel):
31
+ """
32
+ 获取用户信息
33
+ """
34
+ logger.info(f"data: {json_data}")
35
+ info = UserInfoResponse(user_name="张三")
36
+ info.temp_data.code = "0000"
37
+ info.temp_data.msg = "查询成功"
38
+ return info.resp()
39
+
40
+
41
+ @user_blueprint.post("login")
42
+ async def user_login(request: UseLoginRequest):
43
+ """
44
+ 用户登录
45
+ """
46
+ logger.info(f"user_id: {request.form_data.user_id}")
47
+ return json(request.form_data.model_dump())
48
+
49
+
50
+ class App(BaseApp):
51
+ """
52
+ 服务示例
53
+ """
54
+
55
+ async def setup_route(self, app: Sanic):
56
+ api = Blueprint.group(url_prefix="api")
57
+ api.append(user_blueprint)
58
+ app.blueprint(api)
59
+
60
+
61
+ if __name__ == "__main__":
62
+ App.run()