go-zero 模板操作

2022-04-22 10:49 更新

模板操作

模板(Template)是數(shù)據(jù)驅(qū)動(dòng)生成的基礎(chǔ),所有的代碼(rest api、rpc、model、docker、kube)生成都會(huì)依賴模板, 默認(rèn)情況下,模板生成器會(huì)選擇內(nèi)存中的模板進(jìn)行生成,而對于有模板修改需求的開發(fā)者來講,則需要將模板進(jìn)行落盤, 從而進(jìn)行模板修改,在下次代碼生成時(shí)會(huì)加載指定路徑下的模板進(jìn)行生成。

使用幫助

NAME:
   goctl template - template operation

USAGE:
   goctl template command [command options] [arguments...]

COMMANDS:
   init    initialize the all templates(force update)
   clean   clean the all cache templates
   update  update template of the target category to the latest
   revert  revert the target template to the latest

OPTIONS:
   --help, -h  show help

模板初始化

NAME:
   goctl template init - initialize the all templates(force update)

USAGE:
   goctl template init [command options] [arguments...]

OPTIONS:
   --home value  the goctl home path of the template

清除模板

NAME:
   goctl template clean - clean the all cache templates

USAGE:
   goctl template clean [command options] [arguments...]

OPTIONS:
   --home value  the goctl home path of the template

回滾指定分類模板

NAME:
   goctl template update - update template of the target category to the latest

USAGE:
   goctl template update [command options] [arguments...]

OPTIONS:
   --category value, -c value  the category of template, enum [api,rpc,model,docker,kube]
   --home value                the goctl home path of the template

回滾模板

NAME:
   goctl template revert - revert the target template to the latest

USAGE:
   goctl template revert [command options] [arguments...]

OPTIONS:
   --category value, -c value  the category of template, enum [api,rpc,model,docker,kube]
   --name value, -n value      the target file name of template
   --home value                the goctl home path of the template

--home 指定模板存儲(chǔ)路徑

模板加載

在代碼生成時(shí)可以通過--home來指定模板所在文件夾,目前已支持指定模板目錄的命令有:

  • goctl api go 詳情可以通過goctl api go --help查看幫助
  • goctl docker 詳情可以通過goctl docker --help查看幫助
  • goctl kube 詳情可以通過goctl kube --help查看幫助
  • goctl rpc new 詳情可以通過goctl rpc new --help查看幫助
  • goctl rpc proto 詳情可以通過goctl rpc proto --help查看幫助
  • goctl model mysql ddl 詳情可以通過goctl model mysql ddl --help查看幫助
  • goctl model mysql datasource 詳情可以通過goctl model mysql datasource --help查看幫助
  • goctl model pg datasource 詳情可以通過goctl model pg datasource --help查看幫助
  • goctl model mongo 詳情可以通過goctl model mongo --help查看幫助

默認(rèn)情況(在不指定--home)會(huì)從$HOME/.goctl目錄下讀取。

使用示例

  • 初始化模板到指定$HOME/template目錄下

$ goctl template init --home $HOME/template
Templates are generated in /Users/anqiansong/template, edit on your risk!

  • 使用$HOME/template模板進(jìn)行g(shù)reet rpc生成

$ goctl rpc new greet --home $HOME/template
Done


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號