# helloblog **Repository Path**: hubstores/helloblog ## Basic Information - **Project Name**: helloblog - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-08-04 - **Last Updated**: 2024-08-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 一、模块说明 - **main.go** 程序入口 - **settings.yaml** 配置文件 - **api** 接口目录 - **config** 存放记录配置的接口目录 - **core** core 初始化操作 - **flag** flag 命令行相关初始化 - **global** global 全局变量包 - **middleware** middleware 中间件 - **models** models 表结构 - **routers** routers 路由目录 - **service** service 项目与服务有关的目录 - **testdata** testdata 测试文件目录 - **utils** utils 常用的一些工具 - **.gitignore** .gitignore 常用的忽略文件

二、swagger使用说明

参考链接:https://github.com/swaggo/swag/blob/master/README_zh-CN.md
注释 描述
description 操作行为的详细说明
description.markdown 应用程序的简短描述。该描述将从名为 endpointname.md 的文件中读取
id 用于标识操作的唯一字符串。在所有 API 操作中必须唯一
tags 每个 API 操作的标签列表,以逗号分隔
summary 该操作的简短摘要
accept API 可以使用的 MIME 类型列表。 请注意,Accept 仅影响具有请求正文的操作,例如 POST、PUT 和 PATCH。 值必须如“Mime 类型”中所述
produce API 可以生成的 MIME 类型的列表。值必须如“Mime 类型”中所述
param 用空格分隔的参数。param name,param type,data type,is mandatory?,comment attribute(optional)
security 每个 API 操作的标签列表,以逗号分隔
success 以空格分隔的成功响应。return code,{param type},data type,comment
failure 以空格分隔的故障响应。return code,{param type},data type,comment response 与 success、failure 作用相同
response 与 success、failure 作用相同
header 以空格分隔的头字段。 return code,{param type},data type,comment
router 以空格分隔的路径定义。 path,[httpMethod]
deprecatedrouter 与 router 相同,但是是 deprecated 的
x-name 扩展字段必须以 x-开头,并且只能使用 json 值
deprecated 将当前 API 操作的所有路径设置为 deprecated
示例
注释 描述
GetTodo 用于标识这个接口的名称
@Summary Get All todoList 用于描述该接口的简要概述
@Description Get All todoList by creator (base or vip) 用于描述该接口的详细描述
Tags todos用于将该接口与 todos 标签相关联
Accept json 用于指定该接口接受的请求头类型
Produce json 用于指定该接口接受的请求头类型
Accept json 用于指定该接口接受的请求头类型
Produce json 用于指定该接口响应的响应头类型
@Param creator query string true “Creator” 用于定义一个请求参数,其中 creator 是参数名称,query 表示它是一个查询参数,string 表示参数类型,true 表示这是一个必需的参数,最后的 “Creator” 是该参数的描述信息; 共 5 个参数: 第一个为参数名,第二为参数类型(),第三个为数据类型,第四个是否必须 true(false),第五个描述信息
@Success 200 {string} string “ok”用于定义一个成功响应,其中 200 表示响应状态码,{string} 表示响应的数据类型,string 表示响应的数据类型的描述信息,“ok” 表示响应的数据的描述信息
@Failure 400 {string} string “bad request” 用于定义一个失败响应,其中 400 表示响应状态码,{string} 表示响应的数据类型,string 表示响应的数据类型的描述信息,“bad request” 表示响应的数据的描述信息
@Failure 500 {string} string “Internal Server Error 用于定义一个失败响应,其中 500 表示响应状态码,{string} 表示响应的数据类型,string 表示响应的数据类型的描述信息,“Internal Server Error” 表示响应的数据的描述信息
@Router /todos [get] 用于定义路由信息,其中 /todos 是接口路径,[get] 表示请求方法为 GET
链接:https://www.nowcoder.com/questionTerminal/5c156b9332084f8cb31c04ced9455eee?toCommentId=19923613&ran=80 来源:牛客网 package main import ( "fmt" ) func main() { a := 100 defer func() { fmt.Println("defer1") }() fmt.Println("a=", a) defer func() { err := recover() if err != nil { fmt.Println(err) } }() defer func() { fmt.Println("defer2") }() fmt.Println("2") panic("hello,panic!") fmt.Println("3") defer func() { fmt.Println("4") }() ) 输出结果: a= 100 2 defer2 hello,panic! defer1 一目了然