Skip to content

Commit

Permalink
feat: support custom tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ucpr committed Apr 10, 2024
1 parent 51fb24f commit 9349950
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type input struct {
hclPath string
outPath string
pkg string
tag string
}

func generate(s schema.Schema, in input) ([]byte, error) {
Expand All @@ -29,7 +30,7 @@ func generate(s schema.Schema, in input) ([]byte, error) {
for j := range table.Columns {
column := table.Columns[j]
tp := toGoTypeString(column.Type)
fmt.Fprintf(buf, "\t%s\t%s\t`db:\"%s\"`\n", toCamelCase(column.Name), tp, column.Name)
fmt.Fprintf(buf, "\t%s\t%s\t`%s:\"%s\"`\n", toCamelCase(column.Name), tp, in.tag, column.Name)
}
fmt.Fprintf(buf, "}\n\n")
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ func main() {
}

func run() error {
var hclPath, outPath, target, pkg string
var hclPath, outPath, target, tag, pkg string
flag.StringVar(&hclPath, "i", "", "input file path")
flag.StringVar(&outPath, "o", "", "output file path")
flag.StringVar(&target, "t", "mysql", "target database")
flag.StringVar(&tag, "tag", "db", "tag name")
flag.StringVar(&pkg, "package", "main", "package name")
flag.Parse()

Expand All @@ -54,6 +55,7 @@ func run() error {
hclPath: hclPath,
outPath: outPath,
pkg: pkg,
tag: tag,
})
if err != nil {
return fmt.Errorf("failed to generate: %w", err)
Expand Down

0 comments on commit 9349950

Please sign in to comment.