This is a customized goctl (v1.8.3-based) that supports the following features:
- support for external types in DTO definitions
- code gen plugin mechanism. shygoctl focus on api file parse and construction of api specification object, and the code generation wa moved to plugin
original package: https://github.com/zeromicro/go-zero
install shygoctl
go install -u github.com/shyandsy/shygoctl
install gozero code template
go install -u github.com/shyandsy/shygoctl_gozero
generate gozero code based on api file
shygoctl api gen -tpn shygoctl_gozero -api test.api -dir ./ --style=goZero
it can specify the source package in import statement like below: (it also support complex type using in Pointer)
import (
"time"
"github.com/shyandsy/shygoctl/common" // specific the source package path
)
type (
Book {
Id []int64 `json:"id"`
common.BaseBook // use types defined in common package
Created time.Time `json:"created"`
Modified *time.Time `json:"modified"`
}
)command to generate code
$ shygoctl api go -api test.api -dir ./ --style=goZeroit wille generate type.go like below
package types
import (
"github.com/shyandsy/shygoctl/common"
"time"
)
Book {
Id []int64 `json:"id"`
common.BaseBook
Created time.Time `json:"created"`
Modified *time.Time `json:"modified"`
}generate gozero code based on api file
shygoctl api gen -tpn shygoctl_gozero -api test.api -dir ./ --style=goZero
the parameter -tpn specify the name of code gen plugin
# this project folder
$ cd shygoctl/demo
# generate code base on test.api
$ shygoctl api go -api test.api -dir ./ --style=goZero The idea is simple. The core workflow operates as follows:
- Shygoctl generates API specification objects
- These specifications are persisted to a file
- The file is passed to the code-generation plugin
- The plugin retains full control over code generation logic
how to develop your own plugin for your language and framework please refer to github.com/shyandsy/shygoctl_gozero