You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
516 B
24 lines
516 B
1 year ago
|
from fastapi import FastAPI
|
||
|
import yaml
|
||
|
|
||
|
app = FastAPI()
|
||
|
|
||
|
data: dict = {}
|
||
|
|
||
|
@app.on_event('startup')
|
||
|
async def startup():
|
||
|
global data
|
||
|
yml = open('config.yaml', 'r', encoding='utf-8')
|
||
|
raw = yml.read()
|
||
|
yml.close()
|
||
|
data = yaml.load(raw, Loader=yaml.FullLoader)
|
||
|
|
||
|
@app.get('/{id}')
|
||
|
def endpoint(id: str):
|
||
|
cabinets = data.get('cabinets', [])
|
||
|
try:
|
||
|
cabinet = next(filter(lambda c: c['id'] == id, cabinets))
|
||
|
return cabinet
|
||
|
except StopIteration:
|
||
|
return '找不到柜体'
|