Code optimized (#523)

* optimized markdown generator

* optimized markdown generator

* optimized markdown generator

* add more comment

* add comment

* add comment

* add comments for rpc tool

* add comments for model tool

* add comments for model tool

* add comments for model tool

* add comments for config tool

* add comments for config tool

* add comments

* add comments

* add comments

* add comments

* add comment

* remove rpc main head info

* add comment

* optimized

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
kingxt
2021-02-26 16:11:47 +08:00
committed by GitHub
parent ef146cf5ba
commit e6ef1fca12
104 changed files with 651 additions and 375 deletions

View File

@@ -1,5 +1,6 @@
package template
// Delete defines a delete template
var Delete = `
func (m *default{{.upperStartCamelObject}}Model) Delete({{.lowerStartCamelPrimaryKey}} {{.dataType}}) error {
{{if .withCache}}{{if .containsIndexCache}}data, err:=m.FindOne({{.lowerStartCamelPrimaryKey}})
@@ -17,4 +18,5 @@ func (m *default{{.upperStartCamelObject}}Model) Delete({{.lowerStartCamelPrimar
}
`
// DeleteMethod defines a delete template for interface method
var DeleteMethod = `Delete({{.lowerStartCamelPrimaryKey}} {{.dataType}}) error`

View File

@@ -1,5 +1,6 @@
package template
// Error defines an error template
var Error = `package {{.pkg}}
import "github.com/tal-tech/go-zero/core/stores/sqlx"

View File

@@ -1,3 +1,4 @@
package template
// Field defines a filed template for types
var Field = `{{.name}} {{.type}} {{.tag}} {{if .hasComment}}// {{.comment}}{{end}}`

View File

@@ -1,6 +1,7 @@
package template
var (
// Imports defines a import template for model in cache case
Imports = `import (
"database/sql"
"fmt"
@@ -14,6 +15,7 @@ var (
"github.com/tal-tech/go-zero/tools/goctl/model/sql/builderx"
)
`
// ImportsNoCache defines a import template for model in normal case
ImportsNoCache = `import (
"database/sql"
"fmt"

View File

@@ -1,5 +1,6 @@
package template
// Insert defines a template for insert code in model
var Insert = `
func (m *default{{.upperStartCamelObject}}Model) Insert(data {{.upperStartCamelObject}}) (sql.Result,error) {
{{if .withCache}}{{if .containsIndexCache}}{{.keys}}
@@ -14,4 +15,5 @@ func (m *default{{.upperStartCamelObject}}Model) Insert(data {{.upperStartCamelO
}
`
// InsertMethod defines a interface method template for insert code in model
var InsertMethod = `Insert(data {{.upperStartCamelObject}}) (sql.Result,error)`

View File

@@ -1,5 +1,6 @@
package template
// Model defines a template for model
var Model = `package {{.pkg}}
{{.imports}}
{{.vars}}

View File

@@ -1,5 +1,6 @@
package template
// New defines an template for creating model instance
var New = `
func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) {{.upperStartCamelObject}}Model {
return &default{{.upperStartCamelObject}}Model{

View File

@@ -1,3 +1,4 @@
package template
// Tag defines a tag template text
var Tag = "`db:\"{{.field}}\"`"

View File

@@ -1,5 +1,6 @@
package template
// Types defines a template for types in model
var Types = `
type (
{{.upperStartCamelObject}}Model interface{

View File

@@ -1,5 +1,6 @@
package template
// Update defines a template for generating update codes
var Update = `
func (m *default{{.upperStartCamelObject}}Model) Update(data {{.upperStartCamelObject}}) error {
{{if .withCache}}{{.primaryCacheKey}}
@@ -12,4 +13,5 @@ func (m *default{{.upperStartCamelObject}}Model) Update(data {{.upperStartCamelO
}
`
// UpdateMethod defines an interface method template for generating update codes
var UpdateMethod = `Update(data {{.upperStartCamelObject}}) error`

View File

@@ -2,6 +2,7 @@ package template
import "fmt"
// Vars defines a template for var block in model
var Vars = fmt.Sprintf(`
var (
{{.lowerStartCamelObject}}FieldNames = builderx.RawFieldNames(&{{.upperStartCamelObject}}{})