go zero gorm extension
- add the dependent
go get github.com/SpectatorNan/gorm-zero
- replace template/model in your project with gorm-zero/template/{goctl version}/model
- generate
goctl model mysql -src={patterns} -dir={dir} -cache --home ./template
type Config struct {
Mysql gormc.Mysql
...
}
func NewServiceContext(c config.Config) *ServiceContext {
db, err := gormc.ConnectMysql(c.Mysql)
if err != nil {
log.Fatal(err)
}
...
}
type Config struct {
PgSql gormc.PgSql
...
}
func NewServiceContext(c config.Config) *ServiceContext {
db, err := gormc.ConnectPgSql(c.PgSql)
if err != nil {
log.Fatal(err)
}
...
}
- go zero model example link: gorm-zero-example