ast

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImportsHeads = map[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

Functions

func IntoAbbrTableName added in v0.3.0

func IntoAbbrTableName(tableName string) string

IntoAbbrTableName 获取表名缩写

func IntoComment added in v0.3.0

func IntoComment(comment, defaultComment, old, new string) string

IntoComment 转换注释

func IntoImports added in v0.3.0

func IntoImports(s []*Struct) map[string]struct{}

func MatchEnumAnnotation added in v0.1.1

func MatchEnumAnnotation(comment string) string

MatchEnumAnnotation 匹配枚举注解

func ParseEnumAnnotation added in v0.1.1

func ParseEnumAnnotation(annotation string) (map[string][]string, error)

ParseEnumAnnotation 解析枚举注解.

func ParseProtobuf added in v0.3.0

func ParseProtobuf(structName, tableName string, structFields []Field) ([]ProtobufMessageField, []*ProtobufEnum)

Types

type Field

type Field struct {
	FieldName    string // field name
	FieldType    string // field type
	FieldComment string // field comment
	FieldTag     string // field tag merge from FieldTags
	ColumnGoType 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"` // 我是一个注释

FieldTag

key   v1 sep v2 ...
 |     | |
 v     v v
json:"foo,omitempty"

type FieldTagValues added in v0.3.0

type FieldTagValues struct {
	Separate string   // tag separate like [",", ";", " "]
	Value    []string // tag value
}

FieldTagValues field tag values

func NewFiledTagValues added in v0.3.0

func NewFiledTagValues() *FieldTagValues

NewFiledTagValues new FieldTagValues instance with default separate `,`.

func (*FieldTagValues) AddValue added in v0.3.0

func (f *FieldTagValues) AddValue(value string) *FieldTagValues

AddValue add value

func (*FieldTagValues) IsZero added in v0.3.0

func (f *FieldTagValues) IsZero() bool

IsZero value number is zero

func (*FieldTagValues) RemoveValue added in v0.3.0

func (f *FieldTagValues) RemoveValue(value string) *FieldTagValues

RemoveValue remove value

func (*FieldTagValues) SetSeparate added in v0.3.0

func (f *FieldTagValues) SetSeparate(separate string) *FieldTagValues

SetSeparate set separate.

type FieldTags added in v0.3.0

type FieldTags struct {
	// contains filtered or unexported fields
}

FieldTags contains multiple tags

key   v1 sep v2 ...
 |     | |
 v     v v
json:"foo,omitempty"

func NewFieldTags added in v0.3.0

func NewFieldTags() *FieldTags

func (*FieldTags) Add added in v0.3.0

func (f *FieldTags) Add(key string, tagValue *FieldTagValues) *FieldTags

Add add a tag.

func (*FieldTags) AddTagValue added in v0.3.0

func (f *FieldTags) AddTagValue(key, value string) *FieldTags

AddTagValue add a tag value

func (*FieldTags) Get added in v0.3.0

func (f *FieldTags) Get(key string) *FieldTagValues

Get Add a tag

func (*FieldTags) IntoFieldTag added in v0.3.0

func (f *FieldTags) IntoFieldTag() string

func (*FieldTags) Remove added in v0.3.0

func (f *FieldTags) Remove(key string) *FieldTags

Remove remove a tag.

func (*FieldTags) RemoveTagValue added in v0.3.0

func (f *FieldTags) RemoveTagValue(key, value string) *FieldTags

RemoveTagValue remove a tag value

func (*FieldTags) SetTagSeparate added in v0.3.0

func (f *FieldTags) SetTagSeparate(key, sep string) *FieldTags

SetTagSeparate set the tag separate

type File

type File struct {
	Version     string
	Filename    string              // file name
	PackageName string              // package name
	Imports     map[string]struct{} // import package
	Structs     []*Struct           // struct list in file
}

File a file

func (*File) GetProtobufEnums added in v0.3.0

func (p *File) GetProtobufEnums() []*ProtobufEnum

type ProtobufEnum

type ProtobufEnum struct {
	EnumName    string              // 枚举名称,表名+列名
	EnumComment string              // 枚举注释
	EnumFields  []ProtobufEnumField // 枚举字段
}

ProtobufEnum protobuf enum

func ParseEnumComment added in v0.3.0

func ParseEnumComment(structName, tableName, fieldName, columnName, comment string) *ProtobufEnum

ParseEnumComment parse enum comment

type ProtobufEnumField

type ProtobufEnumField struct {
	Id      int    // 段序号
	Name    string // 段名称 uppercase(表名_列名_段名)
	Mapping string // 段映射值
	Comment string // 段注释
}

ProtobufEnumField protobuf enum field enum comment format: {"0":["name","mapping","comment"]}

type ProtobufEnumFieldSlice

type ProtobufEnumFieldSlice []ProtobufEnumField

ProtobufEnumFieldSlice protobuf enum field slice

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 ProtobufEnumFile added in v0.3.0

type ProtobufEnumFile struct {
	Version string
	Package string
	Options map[string]string
	Enums   []*ProtobufEnum
}

type ProtobufMessageField

type ProtobufMessageField struct {
	FieldDataType   string // 列数据类型
	FieldName       string // 列名称
	FieldComment    string // 列注释
	FieldAnnotation string // 列注解
	IsTimestamp     bool   // 是否是时间类型
}

type SqlFile added in v0.3.0

type SqlFile struct {
	Version string
	Tables  []TableAttribute
}

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.
	AbbrTableName      string                 // struct abbreviate table name
	CreateTableSQL     string                 // create table SQL
	ProtoMessageFields []ProtobufMessageField // proto message field
	ProtoEnum          []*ProtobufEnum        // proto enum, parse from comment
}

Struct define a struct

type TableAttribute added in v0.3.0

type TableAttribute struct {
	Name           string // table name, 表名
	Comment        string // table comment, 表注释
	CreateTableSQL string // Create SQL statements, 创建表的sql语句
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL