mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat: config auto load
This commit is contained in:
33
config.py
Normal file
33
config.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import json
|
||||
import os
|
||||
from common.log import logger
|
||||
|
||||
config = {}
|
||||
|
||||
|
||||
def load_config():
|
||||
global config
|
||||
config_path = "config.json"
|
||||
try:
|
||||
if not os.path.exists(config_path):
|
||||
logger.error('配置文件路径不存在')
|
||||
return
|
||||
config_str = read_file(config_path)
|
||||
# 将json字符串反序列化为dict类型
|
||||
config = json.loads(config_str)
|
||||
logger.info("[INIT] load config: {}".format(config))
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
def get_root():
|
||||
return os.path.dirname(os.path.abspath( __file__ ))
|
||||
|
||||
|
||||
def read_file(path):
|
||||
with open(path, 'r') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def conf():
|
||||
return config
|
||||
Reference in New Issue
Block a user