Skip to content

Commit 7610eaf

Browse files
committed
let generateTagWithCase handle alias
1 parent 2734c36 commit 7610eaf

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

boilingcore/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
TagCaseCamel TagCase = "camel"
2121
TagCaseSnake TagCase = "snake"
2222
TagCaseTitle TagCase = "title"
23+
TagCaseAlias TagCase = "alias"
2324
)
2425

2526
// Config for the running of the commands

boilingcore/templates.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ var templateFunctions = template.FuncMap{
342342
"getTable": drivers.GetTable,
343343
}
344344

345-
func generateTagWithCase(tagName, tagValue string, c TagCase, nullable bool) string {
345+
func generateTagWithCase(tagName, tagValue, alias string, c TagCase, nullable bool) string {
346346
buf := strmangle.GetBuffer()
347347
defer strmangle.PutBuffer(buf)
348348

@@ -356,6 +356,8 @@ func generateTagWithCase(tagName, tagValue string, c TagCase, nullable bool) str
356356
buf.WriteString(strmangle.TitleCase(tagValue))
357357
case TagCaseCamel:
358358
buf.WriteString(strmangle.CamelCase(tagValue))
359+
case TagCaseAlias:
360+
buf.WriteString(alias)
359361
default:
360362
buf.WriteString(tagValue)
361363
}

templates/main/00_struct.go.tpl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@ type {{$alias.UpSingular}} struct {
1616
{{- /* render column alias and column type */ -}}
1717
{{ $colAlias }} {{ $column.Type -}}
1818

19-
{{- /* handle struct tags */ -}}
19+
{{- /*
20+
handle struct tags
21+
StructTagCasing will be replaced with $.StructTagCases
22+
however we need to keep this backward compatible
23+
$.StructTagCasing will only be used when it's set to "alias"
24+
*/ -}}
2025
`
2126
{{- if eq $.StructTagCasing "alias" -}}
2227
{{- generateTags $.Tags $colAlias -}}
23-
{{- generateTagWithCase "json" $colAlias "default" $column.Nullable -}}
24-
{{- generateTagWithCase "yaml" $colAlias "default" $column.Nullable -}}
25-
{{- generateTagWithCase "toml" $colAlias "default" $column.Nullable -}}
26-
{{- generateTagWithCase "boil" $colAlias "default" $column.Nullable -}}
28+
{{- generateTagWithCase "json" $column.Name $colAlias "alias" $column.Nullable -}}
29+
{{- generateTagWithCase "yaml" $column.Name $colAlias "alias" $column.Nullable -}}
30+
{{- generateTagWithCase "toml" $column.Name $colAlias "alias" $column.Nullable -}}
31+
{{- generateTagWithCase "boil" $column.Name $colAlias "alias" $column.Nullable -}}
2732
{{- else -}}
2833
{{- generateTags $.Tags $column.Name }}
29-
{{- generateTagWithCase "json" $column.Name $.StructTagCases.Json $column.Nullable -}}
30-
{{- generateTagWithCase "yaml" $column.Name $.StructTagCases.Yaml $column.Nullable -}}
31-
{{- generateTagWithCase "toml" $column.Name $.StructTagCases.Toml $column.Nullable -}}
32-
{{- generateTagWithCase "boil" $column.Name $.StructTagCases.Boil $column.Nullable -}}
34+
{{- generateTagWithCase "json" $column.Name $colAlias $.StructTagCases.Json $column.Nullable -}}
35+
{{- generateTagWithCase "yaml" $column.Name $colAlias $.StructTagCases.Yaml $column.Nullable -}}
36+
{{- generateTagWithCase "toml" $column.Name $colAlias $.StructTagCases.Toml $column.Nullable -}}
37+
{{- generateTagWithCase "boil" $column.Name $colAlias $.StructTagCases.Boil $column.Nullable -}}
3338
{{- end -}}
3439
`
3540
{{ end -}}

0 commit comments

Comments
 (0)