deepscan

package
v0.0.0-...-0e75cad Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Criteria

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

func NewCriteria

func NewCriteria(args ...CriteriaArg) (Criteria, error)

NewCriteria build search Criteria for analyse

type CriteriaArg

type CriteriaArg = func(*Criteria)

func WithAnalyseScope

func WithAnalyseScope(scope string) CriteriaArg

WithAnalyseScope set full abs path to some project directory can be project root, or some child directory, like 'internal' only this directory and it`s child will be analysed for params

func WithExcludedFileMatchers

func WithExcludedFileMatchers(matchers []*regexp.Regexp) CriteriaArg

WithExcludedFileMatchers define list of regexp matchers that will match each file name in analyse scope if regexp match file name, it will be analysed for params

func WithExcludedPath

func WithExcludedPath(paths []string) CriteriaArg

WithExcludedPath define list of abs path directories for exclude from analyse scope

func WithPackagePath

func WithPackagePath(path string) CriteriaArg

WithPackagePath set full abs path to go package who will be analysed

type Gate

type Gate struct {
	MethodName         string           // function name (func Hello(a,b int), name="Hello")
	ParamName          string           // function param name (func (_a_,b int), name="a")
	Index              int              // function param index (func (a,b bool, c int), for c index=2)
	MethodDefinition   Source           // where method is defined
	ArgumentDefinition Source           // where method param type defined (func (a,b,c _int_))
	Interface          Interface        // used interface for injection
	Implementations    []Implementation // all code links to this param
	IsVariadic         bool             // function param is variadic (func (a bool, nums ...int))
}

type Implementation

type Implementation struct {
	Injector Injector // who inject Target to Gate.FunctionName
	Target   Target   // what is injected into Gate.FunctionName
}

type InjectionMethod

type InjectionMethod struct {
	Name       string // method name (example: `NewProcessor`)
	Definition Source // where method is defined
	Gates      []Gate // method params with interface type
}

type Injector

type Injector struct {
	CodeName         string // code expression (not unique)
	MethodDefinition Source // where method is called
	ParamDefinition  Source // where param is passed to method (injection occurs)
}

type Interface

type Interface struct {
	Name       string // interface name
	Definition Source // where interface defined
	GoType     string // interface go type
}

type Searcher

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

func NewSearcher

func NewSearcher() *Searcher

func (*Searcher) Usages

func (s *Searcher) Usages(c Criteria) ([]InjectionMethod, error)

Usages share same packages cache for every function call so it`s good idea to check every package in project with same Searcher instance

This method will find all package functions with interfaces and link it to all callers, with implementations it will skip:

  • methods without interface (not injectable)
  • private methods (nobody outside can call it)
  • only write chan (func (ch chan<-) (our code send something, so we not depend on implementations)
  • with placeholder param names (func (_ myInterface)), nobody can use _, so code not depend on interface

Can`t search from multiple goroutines, but safe for concurrent use (mutex inside)

type Source

type Source struct {
	Pkg    string           // package name (example: "a")
	Import string           // package full import path (example: "example.com/myProject/internal/a")
	Path   string           // package full abs path (example: "/home/user/go/src/myProject/internal/a")
	Place  common.Reference // exactly place in source code
}

type Target

type Target struct {
	StructName string // interface implementation type name
	Definition Source // where this type defined
}

Jump to

Keyboard shortcuts

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