go_annotation

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 11 Imported by: 0

README

Release Coverage Status

go-annotation

Implemented the functionality of Java-like annotations in golang using code generation

Documentation

Index

Constants

View Source
const AnnotationPrefix = "@"

Variables

This section is empty.

Functions

func GetFileNames

func GetFileNames(directory string) ([]string, error)

Types

type Annotation

type Annotation struct {
	Name       string              // 注解名称
	Attributes []map[string]string // 注解属性
}

Annotation 注解

type AnnotationMode

type AnnotationMode string // 注解模式
const (
	AnnotationModeArray AnnotationMode = "array" // 数组注解模式
	AnnotationModeMap   AnnotationMode = "map"   // map注解模式
)

type AnnotationParser

type AnnotationParser interface {
	Parse(comments []string) map[string]*Annotation
}

type ArrayAnnotationParser

type ArrayAnnotationParser struct{}

func (*ArrayAnnotationParser) Parse

func (a *ArrayAnnotationParser) Parse(comments []string) map[string]*Annotation

type Field

type Field struct {
	Name         string //  字段名
	DataType     string // 字段类型
	PackageName  string // 包名
	RealDataType string // 真实类型 不含指针
	IsPtr        bool   // 是否是指针
}

Field 字段信息(入参、出参)

type FileDesc

type FileDesc struct {
	PackageName     string // 包名
	FullPackageName string // 完整包名
	FileName        string // 文件名
	//RelativePath string // todo 相对路径
	Imports    map[string]*ImportDesc
	Structs    []*StructDesc
	Interfaces []*InterfaceDesc
}

FileDesc 文件信息

func GetFileDesc

func GetFileDesc(fileName string, mode AnnotationMode) (*FileDesc, error)

GetFileDesc 获取文件描述 fileName: 文件名

func GetFilesDescList

func GetFilesDescList(directory string, mode AnnotationMode) ([]*FileDesc, error)

GetFilesDescList 获取文件描述列表 directory: 目录

type FileParser

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

func GetFileParser

func GetFileParser(filePath string) *FileParser

func (*FileParser) Parse

func (f *FileParser) Parse() (*FileDesc, error)

type ImportDesc

type ImportDesc struct {
	Name     string // 包名
	HasAlias bool   // 是否有别名
	Path     string // 路径
}

ImportDesc import信息

type InterfaceDesc

type InterfaceDesc struct {
	Name        string                 // 接口名
	Imports     map[string]*ImportDesc // 导入信息
	Comments    []string               // 注释
	Annotations map[string]*Annotation // 注解
	Methods     []*MethodDesc          // 方法
	Description string                 // 描述
}

InterfaceDesc 接口信息

type InterfaceParser

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

func NewInterfaceParser

func NewInterfaceParser(
	serviceName string,
	typeSpec *ast.TypeSpec,
	genDecl *ast.GenDecl,
	fileImports map[string]*ImportDesc) *InterfaceParser

func (*InterfaceParser) Parse

func (s *InterfaceParser) Parse() (*InterfaceDesc, error)

type MapAnnotationParser

type MapAnnotationParser struct{}

func (*MapAnnotationParser) Parse

func (a *MapAnnotationParser) Parse(comments []string) map[string]*Annotation

type MethodDesc

type MethodDesc struct {
	Name        string                 // 方法名
	Description string                 // 描述
	Comments    []string               // 注释
	Annotations map[string]*Annotation // 注解
	Params      []*Field               // 参数
	Results     []*Field               // 返回值
}

MethodDesc 方法信息

type StructDesc

type StructDesc struct {
	Name        string                 // 结构体名
	Imports     map[string]*ImportDesc // 导入信息
	Comments    []string               // 注释
	Annotations map[string]*Annotation // 注解
	//Fields      []*Field               // 字段 暂不支持
	Methods     []*MethodDesc // 方法
	Description string        // 描述
}

StructDesc 结构体信息

type StructParser

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

func NewStructParser

func NewStructParser(serviceName string,
	typeSpec *ast.TypeSpec,
	genDecl *ast.GenDecl,
	file *ast.File,
	fileImports map[string]*ImportDesc) *StructParser

func (*StructParser) Parse

func (s *StructParser) Parse() (*StructDesc, error)

Directories

Path Synopsis
cmd
test

Jump to

Keyboard shortcuts

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