structs for models
This commit is contained in:
@@ -1 +1,23 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
)
|
||||
|
||||
type Field struct {
|
||||
Name string
|
||||
Type ast.Expr
|
||||
Tags *string
|
||||
Options []string // contains options like "autoCreateTime" or "null"
|
||||
Params []string // contains params like "foreignKey:CustomerId" or "constrain:OnDelete:Cascade"
|
||||
Position token.Pos
|
||||
Comment string
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
Name string
|
||||
Fields map[string]Field
|
||||
Position token.Pos
|
||||
Comment string
|
||||
}
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
package common
|
||||
|
||||
import "strings"
|
||||
|
||||
func NormalizeStructTags(tags string) string {
|
||||
// todo: process case with check with ';' literal
|
||||
tagWithoutQuotes := tags[1 : len(tags)-1]
|
||||
tagWithoutSemicolons := strings.ReplaceAll(tagWithoutQuotes, ";", ",")
|
||||
return tagWithoutSemicolons
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ func isGormValueNullable(tags *structtag.Tags) (*bool, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
gormTag.Options = append([]string{gormTag.Name}, gormTag.Options...)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
gormTag.Options = append([]string{gormTag.Name}, gormTag.Options...)
|
||||
|
||||
nullTagExist := gormTag.HasOption("null")
|
||||
notNullTagExist := gormTag.HasOption("not null")
|
||||
|
||||
@@ -47,8 +47,8 @@ func CheckFieldNullConsistency(field ast.Field, structName string, structTags st
|
||||
tags, err := structtag.Parse(structTags)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Invalid structure tag: %s", err))
|
||||
|
||||
}
|
||||
|
||||
if tags == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user