your-workflow/backend/app/core/config.py

25 lines
620 B
Python

import json
from pathlib import Path
import asyncio
CONFIG_PATH = Path(__file__).parent.parent / "config" / "init.json"
def _sync_load_config() -> dict:
with CONFIG_PATH.open("r", encoding="utf-8") as f:
return json.load(f)
def _sync_save_config(config_data: dict):
with CONFIG_PATH.open("w", encoding="utf-8") as f:
json.dump(config_data, f, indent=4, ensure_ascii=False)
# 异步接口
async def load_init_config() -> dict:
return await asyncio.to_thread(_sync_load_config)
async def save_init_config(config_data: dict):
await asyncio.to_thread(_sync_save_config, config_data)