Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Jul 9, 2022
1 parent ff89925 commit 4c57511
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions tools/goctl/api/docgen/doc.go
Expand Up @@ -21,11 +21,13 @@ func genDoc(api *spec.ApiSpec, dir, filename string) error {
if len(api.Service.Routes()) == 0 {
return nil
}

fp, _, err := util.MaybeCreateFile(dir, "", filename)
if err != nil {
return err
}
defer fp.Close()

var builder strings.Builder
for index, route := range api.Service.Routes() {
routeComment := route.JoinedDoc()
Expand Down Expand Up @@ -61,6 +63,7 @@ func genDoc(api *spec.ApiSpec, dir, filename string) error {

builder.Write(tmplBytes.Bytes())
}

_, err = fp.WriteString(strings.Replace(builder.String(), """, `"`, -1))
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/model/cmd.go
Expand Up @@ -83,7 +83,7 @@ func init() {

mongoCmd.Flags().StringSliceVarP(&mongo.VarStringSliceType, "type", "t", nil, "Specified model type name")
mongoCmd.Flags().BoolVarP(&mongo.VarBoolCache, "cache", "c", false, "Generate code with cache [optional]")
mongoCmd.Flags().BoolVarP(&mongo.VarBoolEasy, "easy", "e", false, "Generate code with Auto generated CollectionName for easy declare [optional]")
mongoCmd.Flags().BoolVarP(&mongo.VarBoolEasy, "easy", "e", false, "Generate code with auto generated CollectionName for easy declare [optional]")
mongoCmd.Flags().StringVarP(&mongo.VarStringDir, "dir", "d", "", "The target dir")
mongoCmd.Flags().StringVar(&mongo.VarStringStyle, "style", "", "The file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]")
mongoCmd.Flags().StringVar(&mongo.VarStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
Expand Down
6 changes: 2 additions & 4 deletions tools/goctl/model/mongo/template/model_custom.tpl
Expand Up @@ -6,7 +6,7 @@ package model
){{else}}import "github.com/zeromicro/go-zero/core/stores/mon"{{end}}

{{if .Easy}}
const {{.Type}}CollectionName = "{{.snakeType}}"
const {{.Type}}CollectionName = "{{.snakeType}}"
{{end}}

var _ {{.Type}}Model = (*custom{{.Type}}Model)(nil)
Expand All @@ -30,11 +30,9 @@ type (
return &custom{{.Type}}Model{
default{{.Type}}Model: newDefault{{.Type}}Model(conn),
}
}
{{else}}func New{{.Type}}Model(url, db, collection string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
}{{else}}func New{{.Type}}Model(url, db, collection string{{if .Cache}}, c cache.CacheConf{{end}}) {{.Type}}Model {
conn := {{if .Cache}}monc{{else}}mon{{end}}.MustNewModel(url, db, collection{{if .Cache}}, c{{end}})
return &custom{{.Type}}Model{
default{{.Type}}Model: newDefault{{.Type}}Model(conn),
}
}{{end}}

0 comments on commit 4c57511

Please sign in to comment.