refactor code

master v1.0.10
kevin 4 years ago
parent 3a4e1cbb33
commit 8dd93d59a0

@ -57,6 +57,7 @@ func genLogicByRoute(dir string, group spec.Group, route spec.Route) error {
if !ok { if !ok {
return fmt.Errorf("missing handler annotation for %q", route.Path) return fmt.Errorf("missing handler annotation for %q", route.Path)
} }
handler = strings.TrimSuffix(handler, "handler") handler = strings.TrimSuffix(handler, "handler")
handler = strings.TrimSuffix(handler, "Handler") handler = strings.TrimSuffix(handler, "Handler")
filename := strings.ToLower(handler) filename := strings.ToLower(handler)
@ -65,6 +66,7 @@ func genLogicByRoute(dir string, group spec.Group, route spec.Route) error {
if err != nil { if err != nil {
return err return err
} }
if !created { if !created {
return nil return nil
} }
@ -74,11 +76,11 @@ func genLogicByRoute(dir string, group spec.Group, route spec.Route) error {
if err != nil { if err != nil {
return err return err
} }
imports := genLogicImports(route, parentPkg)
responseString := "" imports := genLogicImports(route, parentPkg)
returnString := "" var responseString string
requestString := "" var returnString string
var requestString string
if len(route.ResponseType.Name) > 0 { if len(route.ResponseType.Name) > 0 {
resp := strings.Title(route.ResponseType.Name) resp := strings.Title(route.ResponseType.Name)
responseString = "(*types." + resp + ", error)" responseString = "(*types." + resp + ", error)"
@ -104,6 +106,7 @@ func genLogicByRoute(dir string, group spec.Group, route spec.Route) error {
if err != nil { if err != nil {
return err return err
} }
formatCode := formatCode(buffer.String()) formatCode := formatCode(buffer.String())
_, err = fp.WriteString(formatCode) _, err = fp.WriteString(formatCode)
return err return err

@ -16,9 +16,7 @@ const (
spatial spatial
) )
const ( const timeImport = "time.Time"
timeImport = "time.Time"
)
type ( type (
Table struct { Table struct {
@ -26,10 +24,12 @@ type (
PrimaryKey Primary PrimaryKey Primary
Fields []Field Fields []Field
} }
Primary struct { Primary struct {
Field Field
AutoIncrement bool AutoIncrement bool
} }
Field struct { Field struct {
Name stringx.String Name stringx.String
DataBaseType string DataBaseType string
@ -38,6 +38,7 @@ type (
IsPrimaryKey bool IsPrimaryKey bool
Comment string Comment string
} }
KeyType int KeyType int
) )

Loading…
Cancel
Save