我正在尝试返回一个 JSON 响应,如下所示:
c.JSON(http.StatusOK, gin.H{"data": resp, "code": http.StatusOK, "status": "success"})
Run Code Online (Sandbox Code Playgroud)
其中 resp 包含来自我已转换为 JSON 的数据库表(结构)的数据。
我需要以这种格式返回数据键中的响应:
data["result"] = resp
示例响应应如下所示:
{
"data": {"result" : ["This is a sample response"]}
}
Run Code Online (Sandbox Code Playgroud)
响应可以是一个对象或对象列表。这是 Python 格式,我如何在 Go 中执行此操作?
我对龙卷风还比较陌生,如果条件通过,我将尝试停止执行方法,否则应继续执行下一行代码(类似于return)
这是我的代码卡住的部分,
class PostMatchHandler(BaseRequestHandler):
result1 = "some sql query".execute()
if not result1:
response.update({'info': 'Levels Completed', 'status': settings.STATUS_200})
self.write(response)
self.finish()
else:
result1 = result1[0]
do_something()
self.write(response)
Run Code Online (Sandbox Code Playgroud)
BaseRequestHandler是:
class BaseRequestHandler(tornado.web.RequestHandler):
"""
Base Class for all the future classes
Activities like logging should be done in this class.
Allow cors request in this class
"""
def set_default_headers(self):
print "setting headers!!!"
def write_error(self, status_code, **kwargs):
response = {}
handle_error_messages..
self.write(response)
@staticmethod
def extract_psycopg2_integrity_error(error):
return error.message.split("Key")[1].replace("(", "").replace(")", "").split(".")[0].replace("=", " ")
def prepare(self):
logging.debug(
"[info] Class …Run Code Online (Sandbox Code Playgroud) 我必须根据难度级别从我的问题集中提取12个问题.以下是我写的查询.
(SELECT q.question_text, q.option_a, q.option_b, q.option_c, q.option_d,
q.correct_answer, q.image_link, q.question_type
FROM questions_bank q
JOIN sports_type st ON st.id = q.sports_type_id
JOIN difficulty_level dl ON dl.id = q.difficulty_level_id
WHERE st.game_type = LOWER('cricket') AND dl.value = 'E'
ORDER BY random()
LIMIT 7)
UNION
(SELECT q.question_text, q.option_a, q.option_b, q.option_c, q.option_d,
q.correct_answer, q.image_link, q.question_type
FROM questions_bank q
JOIN sports_type st ON st.id = q.sports_type_id
JOIN difficulty_level dl ON dl.id = q.difficulty_level_id
WHERE st.game_type = LOWER('cricket') AND dl.value = 'M'
ORDER BY random()
LIMIT 4) …Run Code Online (Sandbox Code Playgroud)