Documentation
¶
Index ¶
- func AnyNode() match.GoNode
- func AnyOf(matchers ...match.GoNode) match.GoNode
- func ArrayType(elt, l match.GoNode) match.GoNode
- func BasicLit(value string) match.GoNode
- func BootFunc() []match.GoNode
- func CallExpr(fun match.GoNode, args GoNodes) match.GoNode
- func Commands() []match.GoNode
- func CompositeLit(t match.GoNode) match.GoNode
- func Config(key string) []match.GoNode
- func EqualNode(n dst.Node) match.GoNode
- func Filters() []match.GoNode
- func FirstOf(n match.GoNode) match.GoNode
- func FoundationSetup() []match.GoNode
- func Func(name match.GoNode) match.GoNode
- func Ident(name string) match.GoNode
- func Import(path string, name ...string) match.GoNode
- func Imports() []match.GoNode
- func Jobs() []match.GoNode
- func KeyValueExpr(key, value match.GoNode) match.GoNode
- func LastOf(n match.GoNode) match.GoNode
- func Migrations() []match.GoNode
- func Providers() []match.GoNode
- func ProvidersInConfig() []match.GoNodedeprecated
- func RegisterFunc() []match.GoNode
- func Rules() []match.GoNode
- func Seeders() []match.GoNode
- func SelectorExpr(x, sel match.GoNode) match.GoNode
- func TypeOf[T any](_ T) match.GoNode
- func ValidationFilters() []match.GoNode
- func ValidationRules() []match.GoNode
- type GoNode
- type GoNodes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyNode ¶
AnyNode creates a matcher that matches any node. For example, CallExpr(Ident("print"), GoNodes{AnyNode()}) matches print(x) where x can be any expression.
func AnyOf ¶
AnyOf creates a matcher that succeeds if any of the provided matchers match. For example, AnyOf(Ident("foo"), Ident("bar")) matches either an identifier named "foo" or "bar".
func ArrayType ¶
ArrayType creates a matcher for array type expressions with element and length matchers. For example, ArrayType(Ident("int"), BasicLit("5")) matches [5]int.
func BasicLit ¶
BasicLit creates a matcher for basic literal expressions with a specific value. For example, BasicLit("\"hello\"") matches the string literal "hello".
func BootFunc ¶ added in v1.17.0
BootFunc matches the Boot() method in service providers. This is used to perform actions after all services are registered.
Example usage:
match.GoFile("providers/custom_provider.go").
Find(match.BootFunc()).
Modify(addBootLogic).
Apply()
This matches:
func (receiver *ServiceProvider) Boot(app foundation.Application) {
facades.Route().Get("/health", healthController.Check)
facades.Event().Register(events)
}
func CallExpr ¶
CallExpr creates a matcher for function call expressions with specific function and argument matchers. For example, CallExpr(Ident("fmt.Println"), GoNodes{BasicLit("\"test\"")}) matches fmt.Println("test").
func Commands ¶
Commands matches the Commands() function that returns a slice of console commands. It looks for a function returning []console.Command composite literals.
Example usage:
match.GoFile("providers/custom_provider.go").
Find(match.Commands()).
Modify(addCommandToList(&CustomCommand{})).
Apply()
This matches:
func (receiver *ServiceProvider) Commands() []console.Command {
return []console.Command{
&commands.MigrateCommand{},
&commands.SeedCommand{},
}
}
func CompositeLit ¶
CompositeLit creates a matcher for composite literal expressions with a type matcher. For example, CompositeLit(Ident("Person")) matches Person{} or Person{Name: "John"}.
func Config ¶
Config matches configuration additions in init functions. It searches for config.Add() or facades.Config().Add() calls with the specified key path. The key parameter uses dot notation to represent nested configuration keys.
Example usage:
match.GoFile("config/custom.go").
Find(match.Config("database.connections.mysql")).
Modify(modifyDatabaseConfig).
Apply()
This matches:
func init() {
config.Add("database", map[string]any{
"connections": map[string]any{
"mysql": map[string]any{
"host": "localhost",
},
},
})
}
func EqualNode ¶
EqualNode creates a matcher that checks if a node is equal to the provided node. For example, if target is &dst.Ident{Name: "x"}, then EqualNode(target) matches only identifier nodes with the exact name "x".
func Filters ¶ added in v1.17.0
Filters matches the Filters() function that returns a slice of validation filters. It looks for a function returning []validation.Filter composite literals.
Example usage:
match.GoFile("providers/validation_provider.go").
Find(match.Filters()).
Modify(addFilterToList(&TrimFilter{})).
Apply()
This matches:
func (receiver *ValidationServiceProvider) Filters() []validation.Filter {
return []validation.Filter{
&filters.TrimFilter{},
&filters.SanitizeFilter{},
}
}
func FirstOf ¶
FirstOf creates a matcher that only matches the first element in a parent slice. For example, FirstOf(TypeOf(&dst.ImportSpec{})) matches only the first import statement in the import declarations.
func FoundationSetup ¶ added in v1.17.0
FoundationSetup matches the Boot function containing foundation.Setup() chain calls. It matches both patterns:
- foundation.Setup().WithConfig(...).Start()
- foundation.Setup().WithMiddleware(...).WithConfig(...).Start()
- foundation.Setup().WithCommand(...).Start()
- return foundation.Setup().WithConfig(...).Start()
Example usage:
GoFile("bootstrap/app.go").
Find(match.FoundationSetup()).
Modify(foundationSetupMiddleware(middleware)).
Apply()
func Func ¶
Func creates a matcher for function declarations with a specific name matcher. For example, Func(Ident("main")) matches func main() { ... }.
func Ident ¶
Ident creates a matcher for identifier nodes with a specific name. For example, Ident("x") matches the identifier x in expressions like x = 1 or return x.
func Import ¶
Import creates a matcher for import specifications with a specific path and optional name. For example, Import("fmt") matches import "fmt", and Import("fmt", "f") matches import f "fmt".
func Imports ¶
Imports matches import declaration blocks in Go source files. It identifies GenDecl nodes with IMPORT token type.
Example usage:
match.GoFile("main.go").
Find(match.Imports()).
Modify(addImportToBlock("github.com/goravel/framework")).
Apply()
This matches:
import (
"fmt"
"strings"
"github.com/goravel/framework/facades"
)
func Jobs ¶
Jobs matches the Jobs() function that returns a slice of queue jobs. It looks for a function returning []queue.Job composite literals.
Example usage:
match.GoFile("providers/queue_provider.go").
Find(match.Jobs()).
Modify(addJobToList(&EmailJob{})).
Apply()
This matches:
func (receiver *QueueServiceProvider) Jobs() []queue.Job {
return []queue.Job{
&jobs.EmailJob{},
&jobs.ProcessDataJob{},
}
}
func KeyValueExpr ¶
KeyValueExpr creates a matcher for key-value expressions with specific key and value matchers. For example, KeyValueExpr(Ident("Name"), BasicLit("\"John\"")) matches Name: "John" in struct literals.
func LastOf ¶
LastOf creates a matcher that only matches the last element in a parent slice. For example, LastOf(Ident("return")) matches return only if it's the last statement in a block.
func Migrations ¶
Migrations matches the Migrations() function that returns a slice of database migrations. It looks for a function returning []schema.Migration composite literals.
Example usage:
match.GoFile("providers/migration_provider.go").
Find(match.Migrations()).
Modify(addMigrationToList(&CreateUsersTable{})).
Apply()
This matches:
func (receiver *MigrationServiceProvider) Migrations() []schema.Migration {
return []schema.Migration{
&migrations.CreateUsersTable{},
&migrations.CreatePostsTable{},
}
}
func Providers ¶
Providers matches the Providers() function that returns a slice of service providers. It looks for a function returning []foundation.ServiceProvider composite literals. This is the recommended way to register service providers.
Example usage:
match.GoFile("config/app.go").
Find(match.Providers()).
Modify(addProviderToList(&CustomServiceProvider{})).
Apply()
This matches:
func Providers() []foundation.ServiceProvider {
return []foundation.ServiceProvider{
&auth.ServiceProvider{},
&cache.ServiceProvider{},
}
}
func ProvidersInConfig
deprecated
added in
v1.17.0
Deprecated: ProvidersInConfig represents the old logic of registering service providers inside the `config/app.go` file.
This pattern is deprecated and will be removed in future versions. Please migrate to the new Providers() function-based registration approach. NOTE: in the current internal setup files, ProvidersInConfig is only used for uninstall (not for install). It will continue to serve as an uninstall-only fallback for the next few releases — during which both Providers() and ProvidersInConfig matchers will be supported to ensure backward compatibility with older versions. After that deprecation period, ProvidersInConfig will be removed entirely.
func RegisterFunc ¶ added in v1.17.0
RegisterFunc matches the Register() method in service providers. This is used to register services into the service container during the boot process.
Example usage:
match.GoFile("providers/custom_provider.go").
Find(match.RegisterFunc()).
Modify(addServiceRegistration).
Apply()
This matches:
func (receiver *ServiceProvider) Register(app foundation.Application) {
app.Bind("custom", func() (any, error) {
return &CustomService{}, nil
})
}
func Rules ¶ added in v1.17.0
Rules matches the Rules() function that returns a slice of validation rules. It looks for a function returning []validation.Rule composite literals.
Example usage:
match.GoFile("providers/validation_provider.go").
Find(match.Rules()).
Modify(addRuleToList(&CustomRule{})).
Apply()
This matches:
func (receiver *ValidationServiceProvider) Rules() []validation.Rule {
return []validation.Rule{
&rules.EmailRule{},
&rules.PhoneRule{},
}
}
func Seeders ¶
Seeders matches the Seeders() function that returns a slice of database seeders. It looks for a function returning []seeder.Seeder composite literals.
Example usage:
match.GoFile("providers/seeder_provider.go").
Find(match.Seeders()).
Modify(addSeederToList(&UserSeeder{})).
Apply()
This matches:
func (receiver *SeederServiceProvider) Seeders() []seeder.Seeder {
return []seeder.Seeder{
&seeders.UserSeeder{},
&seeders.PostSeeder{},
}
}
func SelectorExpr ¶
SelectorExpr creates a matcher for selector expressions (e.g., x.sel) with specific matchers. For example, SelectorExpr(Ident("fmt"), Ident("Println")) matches fmt.Println.
func TypeOf ¶
TypeOf creates a matcher that checks if a node is of a specific type T. For example, TypeOf(&dst.CallExpr{}) matches any function call like foo(), bar(x), or fmt.Println("hello").
func ValidationFilters ¶
ValidationFilters matches the filters() function that returns validation filters. It looks for a lowercase filters() function returning []validation.Filter composite literals. This is typically used in validation service providers for internal filter registration.
Example usage:
match.GoFile("validation/setup.go").
Find(match.ValidationFilters()).
Modify(addValidationFilter(&TrimFilter{})).
Apply()
This matches:
func filters() []validation.Filter {
return []validation.Filter{
&filters.Trim{},
&filters.Lowercase{},
}
}
func ValidationRules ¶
ValidationRules matches the rules() function that returns validation rules. It looks for a lowercase rules() function returning []validation.Rule composite literals. This is typically used in validation service providers for internal rule registration.
Example usage:
match.GoFile("validation/setup.go").
Find(match.ValidationRules()).
Modify(addValidationRule(&EmailRule{})).
Apply()
This matches:
func rules() []validation.Rule {
return []validation.Rule{
&rules.Required{},
&rules.Email{},
}
}
Types ¶
type GoNode ¶
type GoNode struct {
// contains filtered or unexported fields
}
GoNode represents a matcher for Go AST nodes with optional position constraints
func (GoNode) MatchCursor ¶
MatchCursor checks if the cursor's current node matches this GoNode matcher. If first or last flags are set, it also verifies the node's position in its parent slice. For example, FirstOf(Ident("x")).MatchCursor(cursor) returns true only if cursor points to the first identifier "x" in its parent slice.
type GoNodes ¶
GoNodes is a collection of GoNode matchers
func AnyNodes ¶
func AnyNodes() GoNodes
AnyNodes creates an empty GoNodes collection that matches any sequence of nodes. For example, CallExpr(Ident("print"), AnyNodes()) matches print() with any number of arguments.
func (GoNodes) MatchNodes ¶
MatchNodes checks if all nodes in the slice match their corresponding matchers. Returns true if the GoNodes collection is empty or all nodes match. For example, GoNodes{Ident("x"), Ident("y")}.MatchNodes(nodes) returns true if nodes contains exactly two identifiers "x" and "y" in that order.