根据api文件生成代码

Golang
327
0
0
2022-07-14
标签   Golang基础

命令

goctl api go -api shorturl.api -dir .

生成目录结构

luwei@luweideMacBook-Pro-2 api % goctl api go -api shorturl.api -dir .

Done.

luwei@luweideMacBook-Pro-2 api % tree

├── etc

│ └── shorturl-api.yaml

├── internal

│ ├── config

│ │ └── config.go

│ ├── handler

│ │ ├── expandhandler.go

│ │ ├── routes.go

│ │ └── shortenhandler.go

│ ├── logic

│ │ ├── expandlogic.go

│ │ └── shortenlogic.go

│ ├── svc

│ │ └── servicecontext.go

│ └── types

│ └── types.go

├── shorturl.api

└── shorturl.go

7 directories, 11 files

luwei@luweideMacBook-Pro-2 api %

官方介绍

├── api

│ ├── etc

│ │ └── shorturl-api.yaml // 配置文件

│ ├── internal

│ │ ├── config

│ │ │ └── config.go // 定义配置

│ │ ├── handler

│ │ │ ├── expandhandler.go // 实现 expandHandler

│ │ │ ├── routes.go // 定义路由处理

│ │ │ └── shortenhandler.go // 实现 shortenHandler

│ │ ├── logic

│ │ │ ├── expandlogic.go // 实现 ExpandLogic

│ │ │ └── shortenlogic.go // 实现 ShortenLogic

│ │ ├── svc

│ │ │ └── servicecontext.go // 定义 ServiceContext

│ │ └── types

│ │ └── types.go // 定义请求、返回结构体

│ ├── shorturl.api

│ └── shorturl.go // main 入口定义

├── go.mod

└── go.sum