from flask import requestfrom flask import jsonifyfrom flask import Blueprintfrom flask import render_templatefrom performance.logic import Logic performance = Blueprint(‘performance‘, __name__, static_folder=‘static‘, template_folder=‘templates‘, url_prefix=‘/performance‘) @performance.route(‘/‘)def index(): """ 首页 """ return render_template("performance.html") @performance.route(‘/api/v1/start‘, methods=[‘POST‘])def api_v1_start(): """ 执行压测 """ data = request.get_json() # 判断host必传 if ‘host‘ not in data or not data[‘host‘]: return jsonify({ ‘status‘: 400, ‘message‘: "invalid paramenter [‘host‘]", ‘data‘: data }) # 判断代码必传 if ‘code‘ not in data or not data[‘code‘]: return jsonify({ ‘status‘: 400, ‘message‘: "invalid paramenter [‘code‘]", ‘data‘: data }) # 执行运行逻辑 try: case_id, _, _ = Logic().start(data) return jsonify({ ‘status‘: 0, ‘message‘: ‘success‘, ‘data‘: case_id }) except Exception as error: return jsonify({ ‘status‘: 500, ‘message‘: str(error), ‘data‘: data, })
原文地址:https://www.cnblogs.com/zhongyehai/p/11286066.html
时间: 2024-10-04 05:40:09