Skip to content

Commit

Permalink
support add other tag
Browse files Browse the repository at this point in the history
  • Loading branch information
fifsky committed Jul 19, 2018
1 parent c98cc50 commit 9621ca8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Attr struct {
type TableInfo struct {
Columns []*Attr
Len int
OtherTag string
TableName string
ShortName string
StructName string
Expand All @@ -34,7 +35,7 @@ import (
)
{{end}}
type {{ .StructName }} struct {
{{ range $i,$v := .Columns }}{{ .StructField }} {{ .Type }} ` + "\u0060" + `json:"{{ .Field }}" db:"{{ .Field }}"` + "\u0060{{ if ne $i $.Len }}\n " + `{{ end }}{{ end }}
{{ range $i,$v := .Columns }}{{ .StructField }} {{ .Type }} ` + "\u0060" + `db:"{{ .Field }}" json:"{{ .Field }}"{{ if ne $.OtherTag "" }} form:"{{ .Field }}"{{ end }}` + "\u0060{{ if ne $i $.Len }}\n " + `{{ end }}{{ end }}
}
func ({{ .ShortName }} *{{ .StructName }}) DbName() string {
Expand All @@ -50,7 +51,7 @@ func ({{ .ShortName }} *{{ .StructName }}) PK() string {
}
`

func ShowStruct(cmd string) error {
func ShowStruct(cmd string, tag string) error {
query := fmt.Sprintf("SHOW FULL COLUMNS FROM %s", cmd)
datas, err := Exec(query)
if err != nil {
Expand All @@ -65,6 +66,7 @@ func ShowStruct(cmd string) error {
}

info := &TableInfo{
OtherTag: tag,
Columns: make([]*Attr, 0),
TableName: cmd,
ShortName: cmd[0:1],
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"
"strings"

_ "github.com/go-sql-driver/mysql"
"github.com/ilibs/gosql"
"github.com/fifsky/genstruct/lib"
)
Expand Down Expand Up @@ -76,7 +77,10 @@ func main() {
if err != nil {
return err
}
err = lib.ShowStruct(cmd)

tag, _ := lib.GetParams(cmds, 2)

err = lib.ShowStruct(cmd,tag)
if err != nil {
return err
}
Expand Down

0 comments on commit 9621ca8

Please sign in to comment.