Skip to content

Commit

Permalink
重构
Browse files Browse the repository at this point in the history
  • Loading branch information
xta6714 committed Jan 13, 2024
1 parent 5266877 commit c092c9d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions field_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gen
import (
"reflect"
"regexp"
"strconv"
"strings"

"github.com/xta6714/gen/core/generate"
Expand Down Expand Up @@ -142,12 +141,17 @@ var (
// FieldJSONTagWithNS specify JSON tag with name strategy
FieldJSONTagWithNS = func(schemaName func(columnName string) (tagContent string)) model.ModifyFieldOpt {
return func(m *model.Field) *model.Field {
var required = strconv.FormatBool(strings.Contains(m.GORMTag.Build(), "not null"))
var required = strings.Contains(m.GORMTag.Build(), "not null")
jsonTag := schemaName(m.ColumnName)
if schemaName != nil {
if required {
jsonTag += ",required"
}

if schemaName != nil && m.Type == "int64" {
m.Tag.Set(field.TagKeyJson, schemaName(m.ColumnName)+",string"+","+required)
} else if schemaName != nil {
m.Tag.Set(field.TagKeyJson, schemaName(m.ColumnName+","+required))
if m.Type == "int64" {
jsonTag += ",string"
}
m.Tag.Set(field.TagKeyJson, jsonTag)
}
return m
}
Expand Down

0 comments on commit c092c9d

Please sign in to comment.