kivyterminal/py/gadget/docs/cn/README.md
2023-12-05 11:11:59 +08:00

66 lines
2.8 KiB
Markdown
Executable File
Raw 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.

# gadget
一个python开发的基于aiohttp的异步应用服务器集成了1用户认证与权健2数据库操作3后台开发必须的包和函数
gadget支持多进程或多主机部署需安装redis在nginx后面提供负载均衡可按照业务需求动态扩展提升系统处理能力。
功能拓展能力提供两种扩展方法gadget源码级扩展或在工作目录的plugins目录下部署扩展的源码
gadget运行需要指定一个工作目录在工作目录中需有以下文件或目录
* conf目录 - 配置文件目录
* logs目录 - 日志文件目录
* plugins目录 - 扩展目录
* i18n目录 - 国际化支持
* files目录可在conf/config.json文件中指定其他位置
* wwwroot目录可在conf/config.json文件中指定其他位置
## 运行环境和依赖
* 操作系统支持Windows MacOS linux
* 数据库支持sqlite3mysql mariadb postgresqlsqlserver oracle teradata华为的guass等源码方式运行时需提供相应数据库的驱动包
* python 3.7以上版本
* redis 当使用redis_storage时需要
* [apppublic](https://github.com/yumoqing/appPublic)
* [sqlor](https://github.com/yumoqing/sqlor)
* [ahserver](https://github.com/yumoqing/ahserver)
* [dataui](https://github.com/yumoqing/dataui)
* 以及apppublic sqlor ahserver和dataui包所依赖的包或模块
## 运行gadget
运行gadget的步骤
1 转到工作目录
2 gadget [ -p port ]
## 配置
gadget的配置信息需放在工作目录的conf/config.json文件中有关配置相关内容请看[config.json](config.md)
## 模版
gadget支持jinja2模版模版中可以使用gadget定义的所有模块变量和函数
## 数据库操作
gadget为每个请求提供数据库操作 gadget不提供跨请求的数据库操作请求中的数据库操作要么整体成功要么整体失败gadget使用[sqlor](https://github/yumoqing/sqlor)提供数据库支持。 请看[数据库操作说明](sql.md)
## 脚本
gadget支持在后台使用受限的python脚本后缀为“.dspy”
## 用户认证和授权
gadget在缺少状态下不做用户认证和权健要提供此功能需在plugins目录下放一个如下形式的脚本
```
# auth.py
from ahserver.auth_api import AuthAPI
from sqlor.dbpools import DBPools
async def checkUserPermission(self, user, path):
“”“
user用户idNone代表没有登录
path访问目录 path等于URL“http(s)://x.com/ll/ll” 中的“/ll/ll"部分
返回值True有权限
False无权限
如果返回False并且user为None返回前端401否则403
”“”
self.info(f'checkUserPermission():{user} access to {path} ..')
# 这里做实际的判断看看user是否有访问path的权限
return True
AuthAPI.checkUserPermission = checkUserPermission
```