Documentation
¶
Index ¶
- Variables
- type Field
- func (e *Field) AddFieldTag(key string, tagValue *FieldTagValue) *Field
- func (e *Field) AddFieldTagValue(key, value string) *Field
- func (e *Field) BuildLine() string
- func (e *Field) GetFieldTagValue(key string) *FieldTagValue
- func (e *Field) RemoveFieldTag(key string) *Field
- func (e *Field) RemoveFieldTagValue(key, value string) *Field
- func (e *Field) SetFieldTagSep(key, sep string) *Field
- type FieldTagValue
- type File
- type ProtobufEnum
- type ProtobufEnumField
- type ProtobufEnumFieldSlice
- type ProtobufMessage
- type ProtobufMessageField
- type Struct
- func (s *Struct) AddStructFields(e ...Field) *Struct
- func (s *Struct) Build() string
- func (s *Struct) BuildColumnNameTemplate() string
- func (s *Struct) BuildProtobufEnumMappingTemplate() string
- func (s *Struct) BuildProtobufEnumTemplate() string
- func (s *Struct) BuildProtobufTemplate() string
- func (s *Struct) BuildSQL() string
- func (s *Struct) BuildTableNameTemplate() string
Constants ¶
This section is empty.
Variables ¶
var ColumnNameTpl = template.Must(template.New("columnNameTemplate").Parse(columnNameTemplate))
var ImportsHeads = map[string]string{
"string": `"string"`,
"time.Time": `"time"`,
"gorm.Model": `"gorm.io/gorm"`,
"fmt": `"fmt"`,
"datatypes.JSON": `"gorm.io/datatypes"`,
"datatypes.Date": `"gorm.io/datatypes"`,
}
ImportsHeads import head options
var ProtobufEnumMappingTpl = template.Must(template.New("protobufEnumMappingTemplate").Parse(protobufEnumMappingTemplate))
var ProtobufEnumTpl = template.Must(template.New("protobufEnumTemplate").Parse(protobufEnumTemplate))
var ProtobufTpl = template.Must(template.New("protobufTemplate").Funcs(template.FuncMap{"add": func(a, b int) int { return a + b }}).Parse(protobufTemplate))
var TableNameTpl = template.Must(template.New("tableNameTemplate").Parse(tableNameTemplate))
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
FieldName string // field name
FieldType string // field type
FieldComment string // field comment
FieldTags map[string]*FieldTagValue // field tags
ColumnDataType string // field column go type
ColumnName string // field column name in database
}
Field of a struct
FieldName FieldType FieldTags FieldComment
| | | |
v v v v
Foo int `json:"foo,omitempty yaml:"foo,omitempty"` // 我是一个注释
FieldTags
key v1 sep v2 ... | | | v v v json:"foo,omitempty"
func (*Field) AddFieldTag ¶
func (e *Field) AddFieldTag(key string, tagValue *FieldTagValue) *Field
AddFieldTag add a tag value
func (*Field) AddFieldTagValue ¶
AddFieldTagValue add a tag value
func (*Field) GetFieldTagValue ¶
func (e *Field) GetFieldTagValue(key string) *FieldTagValue
AddFieldTag Add a tag
func (*Field) RemoveFieldTag ¶
RemoveFieldTag remove a tag value
func (*Field) RemoveFieldTagValue ¶
RemoveFieldTagValue remove a tag value
func (*Field) SetFieldTagSep ¶
SetFieldTagSep set a tag separate
type FieldTagValue ¶
type FieldTagValue struct {
Sep string // tag separate like [",", ";", " "]
Value []string // tag value
}
FieldTagValue field tag value
func NewFiledTagValue ¶
func NewFiledTagValue() *FieldTagValue
NewFiledTagValue new FieldTagValue instance with default separate `,`.
func (*FieldTagValue) AddValue ¶
func (f *FieldTagValue) AddValue(value string) *FieldTagValue
AddValue add value
func (*FieldTagValue) RemoveValue ¶
func (e *FieldTagValue) RemoveValue(value string) *FieldTagValue
RemoveValue remove a tag
func (*FieldTagValue) SetSeparate ¶
func (f *FieldTagValue) SetSeparate(sep string) *FieldTagValue
SetSeparate set separate.
type File ¶
type File struct {
Filename string // file name
PackageName string // package name
Imports map[string]string // import package
Structs []*Struct // struct list in file
IsOutColumnName bool // is out column name
ProtobufPackage string
ProtobufOptions map[string]string
}
File a file
func (*File) BuildProtobufEnum ¶
func (*File) SetOutColumnName ¶
SetOutColumnName set out column name
type ProtobufEnum ¶
type ProtobufEnum struct {
EnumName string // 枚举名称 表名+列名
EnumComment string // 注释
EnumFields []ProtobufEnumField // 枚举字段
}
type ProtobufEnumField ¶
type ProtobufEnumFieldSlice ¶
type ProtobufEnumFieldSlice []ProtobufEnumField
func (ProtobufEnumFieldSlice) Len ¶
func (p ProtobufEnumFieldSlice) Len() int
func (ProtobufEnumFieldSlice) Less ¶
func (p ProtobufEnumFieldSlice) Less(i, j int) bool
func (ProtobufEnumFieldSlice) Swap ¶
func (p ProtobufEnumFieldSlice) Swap(i, j int)
type ProtobufMessage ¶
type ProtobufMessage struct {
StructName string // 结构体名
StructComment string // 结构体注释
TableName string // 表名
AbbrTableName string // 表名缩写
Fields []ProtobufMessageField // 字段列表
Enums []*ProtobufEnum // 枚举列表(解析注释中)
}
type ProtobufMessageField ¶
type Struct ¶
type Struct struct {
StructName string // struct name
StructComment string // struct comment
StructFields []Field // struct field list
TableName string // struct table name in database.
CreateTableSQL string // create table SQL
// contains filtered or unexported fields
}
Struct define a struct
func (*Struct) AddStructFields ¶
AddStructFields Add one or more fields
func (*Struct) BuildColumnNameTemplate ¶
BuildColumnNameTemplate field name mapping column name which in database.
func (*Struct) BuildProtobufEnumMappingTemplate ¶
func (*Struct) BuildProtobufEnumTemplate ¶
func (*Struct) BuildProtobufTemplate ¶
func (*Struct) BuildTableNameTemplate ¶
BuildTableNameTemplate struct implement schema.Tabler.