Skip to content

Commit 178c36e

Browse files
committed
internal/codegen/golang: tweak tag formatting
Rather than inserting the colon at tag construction time, insert it at tag formatting time. This makes the input look a bit more natural. This matters more, as we are about to add another, more distant, place where we insert tags.
1 parent 0f20c17 commit 178c36e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

internal/codegen/golang/field.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Field struct {
1919
func (gf Field) Tag() string {
2020
tags := make([]string, 0, len(gf.Tags))
2121
for key, val := range gf.Tags {
22-
tags = append(tags, fmt.Sprintf("%s\"%s\"", key, val))
22+
tags = append(tags, fmt.Sprintf("%s:\"%s\"", key, val))
2323
}
2424
if len(tags) == 0 {
2525
return ""

internal/codegen/golang/result.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ func buildStructs(req *plugin.CodeGenRequest) []Struct {
7474
for _, column := range table.Columns {
7575
tags := map[string]string{}
7676
if req.Settings.Go.EmitDbTags {
77-
tags["db:"] = column.Name
77+
tags["db"] = column.Name
7878
}
7979
if req.Settings.Go.EmitJsonTags {
80-
tags["json:"] = JSONTagName(column.Name, req.Settings)
80+
tags["json"] = JSONTagName(column.Name, req.Settings)
8181
}
8282
s.Fields = append(s.Fields, Field{
8383
Name: StructName(column.Name, req.Settings),
@@ -283,10 +283,10 @@ func columnsToStruct(req *plugin.CodeGenRequest, name string, columns []goColumn
283283
}
284284
tags := map[string]string{}
285285
if req.Settings.Go.EmitDbTags {
286-
tags["db:"] = tagName
286+
tags["db"] = tagName
287287
}
288288
if req.Settings.Go.EmitJsonTags {
289-
tags["json:"] = JSONTagName(tagName, req.Settings)
289+
tags["json"] = JSONTagName(tagName, req.Settings)
290290
}
291291
gs.Fields = append(gs.Fields, Field{
292292
Name: fieldName,

0 commit comments

Comments
 (0)