1 Star 0 Fork 0

gaogaoss/go-swagger

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
gaogao 提交于 2024-07-30 09:49 . first commit
package main
import (
"log"
"os"
loads "github.com/go-openapi/loads"
flags "github.com/jessevdk/go-flags"
"github.com/go-swagger/go-swagger/examples/todo-list/restapi"
"github.com/go-swagger/go-swagger/examples/todo-list/restapi/operations"
)
// This file was generated by the swagger tool.
// Make sure not to overwrite this file after you generated it because all your edits would be lost!
func main() {
swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
log.Fatalln(err)
}
api := operations.NewTodoListAPI(swaggerSpec)
server := restapi.NewServer(api)
defer server.Shutdown()
parser := flags.NewParser(server, flags.Default)
parser.ShortDescription = `Simple To Do List API`
parser.LongDescription = swaggerSpec.Spec().Info.Description
server.ConfigureFlags()
for _, optsGroup := range api.CommandLineOptionsGroups {
_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
if err != nil {
log.Fatalln(err)
}
}
if _, err := parser.Parse(); err != nil {
code := 1
if fe, ok := err.(*flags.Error); ok {
if fe.Type == flags.ErrHelp {
code = 0
}
}
os.Exit(code)
}
server.ConfigureAPI()
if err := server.Serve(); err != nil {
log.Fatalln(err)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gaogaoss/go-swagger.git
git@gitee.com:gaogaoss/go-swagger.git
gaogaoss
go-swagger
go-swagger
da1ca328b83f

搜索帮助