1 Star 0 Fork 0

reggie/jquery_datatables_backend_test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
datatables_backend.py 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
reggie 提交于 2023-03-21 10:10 . first commit
# *_*coding:utf-8 *_*
# @Author : Reggie
# @Time : 2023/2/17 13:37
from typing import Union
import six
import uvicorn
from datatables_backend import settings, common
from api.router import api_router
app = common.init_app(api_router)
class Application:
def __init__(
self,
gconfig: Union[dict, None] = None,
**options
):
self.gconfig = gconfig
self.uvicorn_kwargs = self._default_uvicorn_kwargs
self.config = self.configure(self.gconfig, **options)
def configure(self, gconfig: Union[dict, None] = None, prefix='agent_gateway.', **options):
"""
configure
:param dict gconfig: a "global" configuration dictionary whose values can be overridden by
keyword arguments to this method
:param str prefix: prefix
:param options: other config
:return:
"""
gconfig = gconfig or {}
# If a non-empty prefix was given, strip it from the keys in the
# global configuration dict
if prefix:
prefixlen = len(prefix)
gconfig = dict((key[prefixlen:], value) for key, value in six.iteritems(gconfig)
if key.startswith(prefix))
config = {}
for k, v in gconfig.items():
config[k] = v
# Override any options with explicit keyword arguments
config.update(options)
self._configure(config)
return config
def _configure(self, config):
if config.get("host"):
self.uvicorn_kwargs["host"] = config.get("host")
if config.get("port"):
self.uvicorn_kwargs["port"] = config.get("port")
if config.get("reload"):
self.uvicorn_kwargs["reload"] = config.get("reload")
if config.get("workers"):
self.uvicorn_kwargs["workers"] = config.get("workers")
if config.get("log_config"):
self.uvicorn_kwargs["log_config"] = config.get("log_config")
@property
def _default_uvicorn_kwargs(self):
return {
"host": settings.HOST,
"port": settings.PORT,
"workers": settings.WORKERS,
"reload": settings.DEBUG,
"log_config": settings.LOG_CONFIG,
}
def run(self):
uvicorn.run(
app=app,
**self.uvicorn_kwargs
)
if __name__ == '__main__':
Application().run()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/reggiepy/jquery_datatables_backend_test.git
git@gitee.com:reggiepy/jquery_datatables_backend_test.git
reggiepy
jquery_datatables_backend_test
jquery_datatables_backend_test
master

搜索帮助

Cb406eda 1850385 E526c682 1850385