Skip to content

Commit

Permalink
add structName & fieldName implements
Browse files Browse the repository at this point in the history
  • Loading branch information
kfly8 committed Aug 7, 2024
1 parent 7b04fcd commit 53979b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 25 additions & 2 deletions internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"context"
"sort"
"unicode"

//"errors"
//"fmt"
Expand Down Expand Up @@ -158,11 +159,33 @@ func buildStructs(req *plugin.GenerateRequest, options *opts.Options) []Struct {
}

func structName(name string, options *opts.Options) string {
return sdk.LowerTitle(name)
if rename := options.Rename[name]; rename != "" {
return rename
}
out := ""
name = strings.Map(func(r rune) rune {
if unicode.IsLetter(r) {
return r
}
if unicode.IsDigit(r) {
return r
}
return rune('_')
}, name)

for _, p := range strings.Split(name, "_") {
if p == "id" {
out += "ID"
} else {
out += strings.Title(p)
}
}

return out;
}

func fieldName(name string, options *opts.Options) string {
return sdk.LowerTitle(name)
return structName(name, options)
}

func perlType(req *plugin.GenerateRequest, options *opts.Options, column *plugin.Column) string {
Expand Down
1 change: 1 addition & 0 deletions internal/opts/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type Options struct {
Package string `json:"package" yaml:"package"`
Rename map[string]string `json:"rename,omitempty" yaml:"rename"`
OutputModelsFileName string `json:"output_models_file_name,omitempty" yaml:"output_models_file_name"`
}

Expand Down

0 comments on commit 53979b3

Please sign in to comment.