gondex

package module
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

gondex

GO source code indexer

Create indexer

indexer := gondex.CreateIndexer()
if e := indexer.Load(); e != nil {
    panic(e)
}

Find all structs by annotation

items := indexer.FindStructByAnnotation("gluon:Config")
for _, item := range items {
    fmt.Printf("Struct: %v\n", item.Id())
}

Find all implementation of the interface

s := indexer.FindInterfaceImplementation("github.com/go-gluon/generator/test/user.TestI")
for _, t := range s {
    fmt.Printf("Struct: %v\n", t.Id())
}    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGoPackage added in v0.12.0

func IsGoPackage(pkgPath string) bool

Types

type AnnotationInfo

type AnnotationInfo struct {
	Name   string
	Params map[string]string
}

AnnotationInfo represents annotation

type AstFuncDecl

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

AstFuncDecl ast function declaration

func (*AstFuncDecl) Annotations

func (a *AstFuncDecl) Annotations(r *regexp.Regexp) map[string]*AnnotationInfo

Annotations returns list of annotations

func (*AstFuncDecl) FuncType

func (a *AstFuncDecl) FuncType() *ast.FuncType

FuncType struct type of the type

type AstInfo

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

AstInfo syntax info

type AstTypeDecl

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

AstFuncDecl ast type declaration

func (*AstTypeDecl) Annotations

func (a *AstTypeDecl) Annotations(r *regexp.Regexp) map[string]*AnnotationInfo

Annotations returns list of annotations

func (*AstTypeDecl) GenDecl

func (a *AstTypeDecl) GenDecl() *ast.GenDecl

GenDecl struct type of the type

func (*AstTypeDecl) InterfaceType

func (a *AstTypeDecl) InterfaceType() *ast.InterfaceType

InterfaceType struct type of the type

func (*AstTypeDecl) StructType

func (a *AstTypeDecl) StructType() *ast.StructType

StructType struct type of the type

type FieldInfo added in v0.6.0

type FieldInfo struct {
	Struct   *FieldStructInfo
	Index    int
	Metadata map[string]string
}

func (*FieldInfo) FieldStructInfo added in v0.6.0

func (f *FieldInfo) FieldStructInfo(named *types.Named, struc *types.Struct) *FieldStructInfo

func (*FieldInfo) Name added in v0.6.0

func (f *FieldInfo) Name() string

func (*FieldInfo) Tag added in v0.6.0

func (f *FieldInfo) Tag() string

func (*FieldInfo) TagValue added in v0.6.0

func (f *FieldInfo) TagValue(name string) (string, bool)

func (*FieldInfo) Type added in v0.6.0

func (f *FieldInfo) Type() types.Type

func (*FieldInfo) Var added in v0.6.0

func (f *FieldInfo) Var() *types.Var

type FieldStructInfo added in v0.6.0

type FieldStructInfo struct {
	Info     *StructInfo
	Parent   *FieldInfo
	Named    *types.Named
	Struct   *types.Struct
	Level    int
	Metadata map[string]string
}

func (*FieldStructInfo) Field added in v0.6.0

func (f *FieldStructInfo) Field(index int) *FieldInfo

func (*FieldStructInfo) Fields added in v0.17.0

func (f *FieldStructInfo) Fields() map[string]*FieldInfo

func (*FieldStructInfo) Name added in v0.6.0

func (f *FieldStructInfo) Name() string

func (*FieldStructInfo) NumFields added in v0.6.0

func (f *FieldStructInfo) NumFields() int

func (*FieldStructInfo) Tag added in v0.6.0

func (f *FieldStructInfo) Tag(index int) string

func (*FieldStructInfo) Var added in v0.6.0

func (f *FieldStructInfo) Var(index int) *types.Var

type FieldStructWalk added in v0.6.0

type FieldStructWalk interface {
	FieldBefore(f *FieldInfo) bool
	FieldAfter(f *FieldInfo)
	Basic(f *FieldInfo, t *types.Basic)
	Interface(f *FieldInfo, n *types.Named, t *types.Interface)
	Array(f *FieldInfo, t *types.Array) bool
	Slice(f *FieldInfo, t *types.Slice) bool
	Map(f *FieldInfo, t *types.Map) (bool, bool)
	Struct(f *FieldInfo, n *types.Named, t *types.Struct) bool
	StructBefore(s *FieldStructInfo) bool
	StructAfter(s *FieldStructInfo)
}

type FunctionInfo

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

FunctionInfo represents function

func (*FunctionInfo) Annotation added in v0.17.0

func (s *FunctionInfo) Annotation(name string) *AnnotationInfo

Annotation returns annotation by name or nil

func (*FunctionInfo) Annotations added in v0.17.0

func (s *FunctionInfo) Annotations() map[string]*AnnotationInfo

Annotations returns list of interface annotations or emtpy list

func (*FunctionInfo) Ast added in v0.17.0

func (s *FunctionInfo) Ast() *AstFuncDecl

Ast declaration of the type

func (*FunctionInfo) Decl

func (s *FunctionInfo) Decl() *AstFuncDecl

Decl ast declaration of the type

func (*FunctionInfo) Func added in v0.17.0

func (s *FunctionInfo) Func() *types.Func

Func func type

func (*FunctionInfo) Id added in v0.17.0

func (s *FunctionInfo) Id() string

Id of the interface

func (*FunctionInfo) Name added in v0.17.0

func (s *FunctionInfo) Name() string

Name of the interface

type Indexer

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

Indexer hold the information about the packages and types

func CreateDefaultIndexer added in v0.7.0

func CreateDefaultIndexer() *Indexer

CreateIndexer creates indexer

func CreateIndexer

func CreateIndexer(config *IndexerConfig) *Indexer

CreateIndexer creates indexer

func (*Indexer) FindInterfaceImplementations added in v0.15.0

func (indexer *Indexer) FindInterfaceImplementations(name string) []*StructInfo

FindInterfaceImplementation find all interface implementations

func (*Indexer) FindInterfacesByAnnotation added in v0.15.0

func (indexer *Indexer) FindInterfacesByAnnotation(name string) []*StructInfo

FindInterfacesByAnnotation find all interfaces by annotation

func (*Indexer) FindStructsByAnnotation added in v0.15.0

func (indexer *Indexer) FindStructsByAnnotation(name string) []*StructInfo

FindStructsByAnnotation find all structs by annotation

func (*Indexer) Interface added in v0.14.0

func (indexer *Indexer) Interface(name string) *InterfaceInfo

Interface returns by name or nil

func (*Indexer) Interfaces

func (indexer *Indexer) Interfaces() map[string]*InterfaceInfo

Interfaces return map of all interfaces

func (*Indexer) Load

func (indexer *Indexer) Load() error

Load load packages by default pattern ./...

func (*Indexer) LoadPattern

func (indexer *Indexer) LoadPattern(pattern ...string) error

LoadPattern load packages by the pattern to the indexer

func (*Indexer) MainModule added in v0.17.0

func (indexer *Indexer) MainModule() *ModuleInfo

func (*Indexer) Module added in v0.17.0

func (indexer *Indexer) Module(path string) *ModuleInfo

Package returns module by module path or nil

func (*Indexer) Modules added in v0.17.0

func (indexer *Indexer) Modules() map[string]*ModuleInfo

Packages return map of all modules

func (*Indexer) Package added in v0.14.0

func (indexer *Indexer) Package(pkgPath string) *PackageInfo

Package returns package by package path or nil

func (*Indexer) Packages

func (indexer *Indexer) Packages() map[string]*PackageInfo

Packages return map of all packages

func (*Indexer) Struct added in v0.14.0

func (indexer *Indexer) Struct(name string) *StructInfo

Struct returns struct by name or nil

func (*Indexer) Structs

func (indexer *Indexer) Structs() map[string]*StructInfo

Structs return map of all structs

type IndexerConfig added in v0.7.0

type IndexerConfig struct {
	DefaultAnnoRegex *regexp.Regexp
	DefaultPattern   []string
	Debug            bool
	SkipGoPackages   bool
	Mode             packages.LoadMode
}

func CreateDefaultConfig added in v0.7.0

func CreateDefaultConfig() *IndexerConfig

CreateIndexer creates indexer

type InterfaceInfo

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

InterfaceInfo represents interface

func (*InterfaceInfo) Annotation added in v0.17.0

func (s *InterfaceInfo) Annotation(name string) *AnnotationInfo

Annotation returns annotation by name or nil

func (*InterfaceInfo) Annotations

func (s *InterfaceInfo) Annotations() map[string]*AnnotationInfo

Annotations returns list of interface annotations or emtpy list

func (*InterfaceInfo) Ast

func (s *InterfaceInfo) Ast() *AstTypeDecl

Ast declaration of the type

func (*InterfaceInfo) Id

func (s *InterfaceInfo) Id() string

Id of the interface

func (*InterfaceInfo) Interface added in v0.16.0

func (s *InterfaceInfo) Interface() *types.Interface

Interface interface type

func (*InterfaceInfo) Name

func (s *InterfaceInfo) Name() string

Name of the interface

type ModuleInfo added in v0.17.0

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

ModuleInfo struct represents the module information

func (*ModuleInfo) Data added in v0.17.0

func (m *ModuleInfo) Data() *packages.Module

func (*ModuleInfo) Name added in v0.17.0

func (m *ModuleInfo) Name() string

func (*ModuleInfo) Version added in v0.17.0

func (m *ModuleInfo) Version() string

type PackageInfo

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

PackageInfo struct represents the package information

func (*PackageInfo) Data

func (p *PackageInfo) Data() *packages.Package

Data of the package

func (*PackageInfo) Id

func (p *PackageInfo) Id() string

ID of the package

type StructInfo

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

StructInfo information about the struct

func (*StructInfo) Annotation added in v0.17.0

func (s *StructInfo) Annotation(name string) *AnnotationInfo

Annotation returns annotation by name or nil

func (*StructInfo) Annotations

func (s *StructInfo) Annotations() map[string]*AnnotationInfo

Annotations returns list of struct annotations or empty list

func (*StructInfo) Ast

func (s *StructInfo) Ast() *AstTypeDecl

Ast ast declaration of the type

func (*StructInfo) FieldStructInfo added in v0.17.0

func (s *StructInfo) FieldStructInfo() *FieldStructInfo

func (*StructInfo) Fields added in v0.6.0

func (s *StructInfo) Fields(walk FieldStructWalk)

func (*StructInfo) Id

func (s *StructInfo) Id() string

Id of the struct

func (*StructInfo) Implements added in v0.14.0

func (s *StructInfo) Implements(interfaceInfo *InterfaceInfo) bool

Implements returns true if struct implments the interface

func (*StructInfo) Name

func (s *StructInfo) Name() string

Name this is the name of the struct

func (*StructInfo) Named

func (s *StructInfo) Named() *types.Named

Named type named of struct

func (*StructInfo) Package

func (s *StructInfo) Package() *PackageInfo

Package struct package info

func (*StructInfo) Struct

func (s *StructInfo) Struct() *types.Struct

Struct type of struct

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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