Documentation ¶
Index ¶
- Constants
- func AddFormerMixins(fileName, nameSpace, alias string) []string
- func CleanImportsWriteGolangFile(fileName string, sourceCode []byte) ([]byte, error)
- func FormatGolangCode(src []byte) ([]byte, error)
- func GetLineFeature(code string) (feature string)
- func GetNameList(ids []*ast.Ident) (names []string)
- func ParseAndMixinFile(fileName string, verbose bool) error
- func RegisterSubstitute(sub *ModelSummary)
- func ReplaceModelFields(cp *CodeParser, node *DeclNode, summary *ModelSummary)
- func RewritePackage(pkgpath, pkgname string) error
- func TrimComment(c string) string
- func WriteCodeFile(fileName string, sourceCode []byte) ([]byte, error)
- func WriteGolangFile(fileName string, sourceCode []byte) ([]byte, error)
- type CodeParser
- type CodeSource
- func (cs *CodeSource) AddCode(code []byte) error
- func (cs *CodeSource) AddImport(path, alias string) bool
- func (cs *CodeSource) AddReplace(first, last ast.Node, code string)
- func (cs *CodeSource) AddStringCode(code string) error
- func (cs *CodeSource) AltSource() ([]byte, bool)
- func (cs *CodeSource) CleanImports() (removes int)
- func (cs *CodeSource) DelImport(path, alias string) bool
- func (cs *CodeSource) GetComment(c *ast.CommentGroup, trim bool) string
- func (cs *CodeSource) GetContent() ([]byte, error)
- func (cs *CodeSource) GetFieldCode(node *DeclNode, i int) string
- func (cs *CodeSource) GetNodeCode(node ast.Node) string
- func (cs *CodeSource) GetPackage() string
- func (cs *CodeSource) GetPackageOffset() int
- func (cs *CodeSource) SetPackage(name string) (err error)
- func (cs *CodeSource) SetSource(source []byte) (err error)
- func (cs *CodeSource) WriteTo(filename string) error
- type DeclNode
- type FieldNode
- type ModelSummary
- type PosAlt
Constants ¶
View Source
const MODEL_EXTENDS = "`json:\",inline\" xorm:\"extends\"`"
Variables ¶
This section is empty.
Functions ¶
func AddFormerMixins ¶
func GetNameList ¶
func ParseAndMixinFile ¶
func RegisterSubstitute ¶
func RegisterSubstitute(sub *ModelSummary)
func ReplaceModelFields ¶
func ReplaceModelFields(cp *CodeParser, node *DeclNode, summary *ModelSummary)
func RewritePackage ¶
将包中的Go文件格式化,如果提供了pkgname则用作新包名
func TrimComment ¶
Types ¶
type CodeParser ¶
type CodeParser struct { DeclNodes []*DeclNode DeclIndexes map[string][]int *CodeSource }
func NewCodeParser ¶
func NewCodeParser() *CodeParser
func NewFileParser ¶
func NewFileParser(filename string) (cp *CodeParser, err error)
func NewSourceParser ¶
func NewSourceParser(source []byte) (cp *CodeParser, err error)
func (*CodeParser) AllDeclNode ¶
func (cp *CodeParser) AllDeclNode(kind string) []*DeclNode
func (*CodeParser) GetDeclNode ¶
func (cp *CodeParser) GetDeclNode(kind string, offset int) *DeclNode
func (*CodeParser) ParseDecls ¶
func (cp *CodeParser) ParseDecls(kind string, limit int) bool
type CodeSource ¶
type CodeSource struct { Fileast *ast.File Fileset *token.FileSet Source []byte Alternates []PosAlt // Source 只能替换一次,然后必须重新解析 Fileast *printer.Config }
func NewCodeSource ¶
func NewCodeSource() *CodeSource
func ResetImports ¶
func ResetImports(cs *CodeSource, imports map[string]string) (*CodeSource, error)
func WithImports ¶
func (*CodeSource) AddCode ¶
func (cs *CodeSource) AddCode(code []byte) error
func (*CodeSource) AddImport ¶
func (cs *CodeSource) AddImport(path, alias string) bool
func (*CodeSource) AddReplace ¶
func (cs *CodeSource) AddReplace(first, last ast.Node, code string)
func (*CodeSource) AddStringCode ¶
func (cs *CodeSource) AddStringCode(code string) error
func (*CodeSource) AltSource ¶
func (cs *CodeSource) AltSource() ([]byte, bool)
func (*CodeSource) CleanImports ¶
func (cs *CodeSource) CleanImports() (removes int)
func (*CodeSource) DelImport ¶
func (cs *CodeSource) DelImport(path, alias string) bool
func (*CodeSource) GetComment ¶
func (cs *CodeSource) GetComment(c *ast.CommentGroup, trim bool) string
func (*CodeSource) GetContent ¶
func (cs *CodeSource) GetContent() ([]byte, error)
func (*CodeSource) GetFieldCode ¶
func (cs *CodeSource) GetFieldCode(node *DeclNode, i int) string
func (*CodeSource) GetNodeCode ¶
func (cs *CodeSource) GetNodeCode(node ast.Node) string
func (*CodeSource) GetPackage ¶
func (cs *CodeSource) GetPackage() string
func (*CodeSource) GetPackageOffset ¶
func (cs *CodeSource) GetPackageOffset() int
func (*CodeSource) SetPackage ¶
func (cs *CodeSource) SetPackage(name string) (err error)
func (*CodeSource) SetSource ¶
func (cs *CodeSource) SetSource(source []byte) (err error)
func (*CodeSource) WriteTo ¶
func (cs *CodeSource) WriteTo(filename string) error
type DeclNode ¶
type DeclNode struct { Token token.Token Kinds []string Names []string Fields []*FieldNode Comment *ast.CommentGroup Offset int ast.Decl }
func NewDeclNode ¶
type ModelSummary ¶
type ModelSummary struct { Name string Substitute string Import, Alias string Features []string FieldLines []string IsChanged bool // contains filtered or unexported fields }
func ReplaceSummary ¶
func ReplaceSummary(summary, sub *ModelSummary) *ModelSummary
func (ModelSummary) GetInnerCode ¶
func (s ModelSummary) GetInnerCode() string
找出 model 内部代码,即在 {} 里面的内容
func (ModelSummary) GetSortedFeatures ¶
func (s ModelSummary) GetSortedFeatures() []string
找出 model 的所有特征并排序
func (*ModelSummary) GetSubstitute ¶
func (s *ModelSummary) GetSubstitute() string
func (*ModelSummary) ParseFields ¶
func (s *ModelSummary) ParseFields(cp *CodeParser, node *DeclNode) int
解析 struct 代码,提取特征并补充注释到代码
Click to show internal directories.
Click to hide internal directories.