make cmd Command 时生成的文件没有内容
1. 运行环境
go version go1.17.5 darwin/amd64
2. 问题描述?
go run main.go make cmd testCommand
[app/cmd/test_command.go] created.
command name:test_command
command variable name: cmd.CmdTestCommand
please edit main.go's app.Commands slice to register command
pkg/file/file.go
// Put 将数据存入文件
func Put(data []byte, to string) error {
err := ioutil.WriteFile(to, data, 0644)
log.Println(ioutil.WriteFile(to, data, 0644))
if err != nil {
return err
}
return nil
}
app/cmd/make/make.go
// createFileFromStub 读取 stub 文件并进行变量替换
func createFileFromStub(filePath string, stubName string, model Model, variables ...interface{}) {
`
`
`
// 读取 stub 模板文件
modelData, _ := stubsFS.ReadFile("stubs/" + stubName + ".stub")
modelStub := string(modelData)
// 对模板内容做变量替换
for search, replace := range replaces {
modelStub = strings.ReplaceAll(modelStub, search, replace)
}
log.Println(modelStub)
`
`
`
}
go run main.go make cmd testCommand
2022/01/08 18:26:57
2022/01/08 18:26:57 <nil>
[app/cmd/test_command.go] created.
command name:test_command
command variable name: cmd.CmdTestCommand
please edit main.go's app.Commands slice to register command
推荐文章: