ast

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColumnNameTpl = template.Must(template.New("columnNameTemplate").Parse(columnNameTemplate))
View Source
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

View Source
var ProtobufEnumMappingTpl = template.Must(template.New("protobufEnumMappingTemplate").Parse(protobufEnumMappingTemplate))
View Source
var ProtobufEnumTpl = template.Must(template.New("protobufEnumTemplate").Parse(protobufEnumTemplate))
View Source
var ProtobufTpl = template.Must(template.New("protobufTemplate").Funcs(template.FuncMap{"add": func(a, b int) int { return a + b }}).Parse(protobufTemplate))
View Source
var TableNameTpl = template.Must(template.New("tableNameTemplate").Parse(tableNameTemplate))

Functions

func BuildRawProtobufEnumHeader added in v0.1.1

func BuildRawProtobufEnumHeader(protobufPackage string, protobufOptions map[string]string) []byte

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 解析枚举注解.

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

func (e *Field) AddFieldTagValue(key, value string) *Field

AddFieldTagValue add a tag value

func (*Field) BuildLine

func (e *Field) BuildLine() string

BuildLine build a field line

func (*Field) GetFieldTagValue

func (e *Field) GetFieldTagValue(key string) *FieldTagValue

AddFieldTag Add a tag

func (*Field) RemoveFieldTag

func (e *Field) RemoveFieldTag(key string) *Field

RemoveFieldTag remove a tag value

func (*Field) RemoveFieldTagValue

func (e *Field) RemoveFieldTagValue(key, value string) *Field

RemoveFieldTagValue remove a tag value

func (*Field) SetFieldTagSep

func (e *Field) SetFieldTagSep(key, sep string) *Field

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) IsEmpty

func (f *FieldTagValue) IsEmpty() bool

IsEmpty value count is empty

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) AddImport

func (p *File) AddImport(imp string) *File

AddImport Add import by type

func (*File) AddStruct

func (p *File) AddStruct(st *Struct) *File

AddStruct Add a structure

func (*File) Build

func (p *File) Build() []byte

Build the file data

func (*File) BuildProtobufEnum

func (p *File) BuildProtobufEnum() []byte

func (*File) BuildProtobufEnumBody added in v0.1.1

func (p *File) BuildProtobufEnumBody() []byte

func (*File) BuildSQL

func (p *File) BuildSQL() []byte

BuildSQL sql in one file

func (*File) SetOutColumnName

func (p *File) SetOutColumnName(b bool) *File

SetOutColumnName set out column name

type ProtobufEnum

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

type ProtobufEnumField

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

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 ProtobufMessageField struct {
	FieldDataType   string // 列数据类型
	FieldName       string // 列名称
	FieldComment    string // 列注释
	FieldAnnotation string // 列注解
	IsTimestamp     bool   // 是否是时间类型
}

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

func (s *Struct) AddStructFields(e ...Field) *Struct

AddStructFields Add one or more fields

func (*Struct) Build

func (s *Struct) Build() string

Build Get the struct data.

func (*Struct) BuildColumnNameTemplate

func (s *Struct) BuildColumnNameTemplate() string

BuildColumnNameTemplate field name mapping column name which in database.

func (*Struct) BuildProtobufEnumMappingTemplate

func (s *Struct) BuildProtobufEnumMappingTemplate() string

func (*Struct) BuildProtobufEnumTemplate

func (s *Struct) BuildProtobufEnumTemplate() string

func (*Struct) BuildProtobufTemplate

func (s *Struct) BuildProtobufTemplate() string

func (*Struct) BuildSQL

func (s *Struct) BuildSQL() string

func (*Struct) BuildTableNameTemplate

func (s *Struct) BuildTableNameTemplate() string

BuildTableNameTemplate struct implement schema.Tabler.

Jump to

Keyboard shortcuts

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