from enum import Enum
from fastapi import FastAPI
app = FastAPI()
# 路径参数枚举值
'''
编程语言三种分类:python java go
'''
# 继承str 枚举Enum
class LangName(str, Enum):
PYTHON = "python"
JAVA = "java"
GO = "go"
@app.get("/it/{lang}")
def lang(lang: LangName):
if lang == LangName.PYTHON:
return {"class": {"msg": "This class is PYTHON", "lang.name": lang.name, "lang.value": lang.value}}
elif lang == LangName.JAVA:
return {"class": {"msg": "This class is JAVA", "lang.name": lang.name, "lang.value": lang.value}}
else:
return {"class": {"msg": "This class is GO", "lang.name": lang.name, "lang.value": lang.value}}
标签:lang,LangName,07,FastAPI,value,枚举,class,name
From: https://www.cnblogs.com/leoshi/p/17247049.html