[TOC]
- 快速產生CRUD template的工具
go install github.com/rickylin614/nunu@v1.0.4
└─template
└─nunu
├─append.yaml
├─handler.tpl
├─model_bo.tpl
├─model_dto.tpl
├─model_po.tpl
├─repository.tpl
├─service.tpl
└─target.yaml
- target.yaml example
target_path:
handler: "./service/internal/controller/handler/"
service: "./service/internal/core/module/"
repository: "./service/internal/repository/"
model:
- path: "./service/internal/model/bo/"
temp_file: "model_bo.tpl"
- path: "./service/internal/model/po/"
temp_file: "model_po.tpl"
- path: "./service/internal/model/dto/"
temp_file: "model_dto.tpl"
- append.yaml example
files:
- path: "internal/handler/provider.go"
regex: "type Handler struct \\{.*?\\}"
template: "\\n\\t{{ .FileName }}Handler *{{ .FileNameTitleLower }}Handler"
- path: "internal/handler/provider.go"
regex: "func NewHandler\\(in digIn\\) .*?Handler \\{.*?\\\t}"
template: "\\n\\t\\t{{ .FileName }}Handler: &{{ .FileNameTitleLower }}Handler{in: in},"
- path: "internal/service/provider.go"
regex: "type Service struct \\{.*?\\}"
template: "\\n\\t{{ .FileName }}Srv I{{ .FileName }}Service"
- path: "internal/service/provider.go"
regex: "func NewService\\(in digIn\\) .*?Service \\{.*?\\\t}"
template: "\\n\\t\\t{{ .FileName }}Srv: New{{ .FileName }}Service(in),"
- path: "internal/repository/provider.go"
regex: "type Repository struct \\{.*?\\}"
template: "\\n\\t{{ .FileName }}Repo I{{ .FileName }}Repository"
- path: "internal/repository/provider.go"
regex: "func NewRepository\\(in digIn\\) .*?Repository \\{.*?\\\t}"
template: "\\n\\t\\t{{ .FileName }}Repo: New{{ .FileName }}Repository(in),"
- nunu create handler
{model}
- auto gen handler.tpl to target directory
- nunu create service
{model}
- auto gen service.tpl to target directory
- nunu create reposotory
{model}
- auto gen reposotory.tpl to target directory
- nunu create model
{model}
- auto gen model.tpl to target directory
- nunu create all
{model}
- auto gen handler & service & reposotory & model
- nunu append
{model}
- 主要藉由正則以及模板,達成在需要依賴註冊的地方添加自己需要的代碼
- nunu upgrade
- 其餘功能同fork的來源倉儲nunu