Documentation
¶
Index ¶
- func Add(expression string) modify.Action
- func AddCommand(pkg, command string) error
- func AddConfig(name, expression string, annotations ...string) modify.Action
- func AddFilter(pkg, filter string) error
- func AddImport(path string, name ...string) modify.Action
- func AddJob(pkg, job string) error
- func AddMiddleware(pkg, middleware string) error
- func AddMigration(pkg, migration string) error
- func AddProvider(pkg, provider string) error
- func AddRoute(pkg, route string) error
- func AddRule(pkg, rule string) error
- func AddSeeder(pkg, seeder string) error
- func Call(fn func(options []modify.Option) error) modify.Apply
- func ExprExists(x []dst.Expr, y dst.Expr) bool
- func ExprIndex(x []dst.Expr, y dst.Expr) int
- func File(path string) modify.File
- func GoFile(file string) modify.GoFile
- func IsUsingImport(df *dst.File, path string, name ...string) bool
- func KeyExists(kvs []dst.Expr, key dst.Expr) bool
- func KeyIndex(kvs []dst.Expr, key dst.Expr) int
- func MustParseExpr(x string) (node dst.Node)
- func Register(expression string, before ...string) modify.Action
- func RegisterMigration(pkg, migration string) modify.Apply
- func RegisterProvider(pkg, provider string) modify.Apply
- func RegisterRoute(pkg, route string) modify.Apply
- func Remove(expression string) modify.Action
- func RemoveConfig(name string) modify.Action
- func RemoveImport(path string, name ...string) modify.Action
- func RemoveMigration(pkg, migration string) error
- func RemoveProvider(pkg, provider string) error
- func RemoveRoute(pkg, route string) error
- func ReplaceConfig(name, expression string) modify.Action
- func Unregister(expression string) modify.Action
- func UnregisterMigration(pkg, migration string) modify.Apply
- func UnregisterProvider(pkg, provider string) modify.Apply
- func UnregisterRoute(pkg, route string) modify.Apply
- func When(fn func(options map[string]any) bool, applies ...modify.Apply) modify.Apply
- func WhenDriver(driver string, applies ...modify.Apply) modify.Apply
- func WhenFacade(facade string, applies ...modify.Apply) modify.Apply
- func WhenFileContains(file, content string, applies ...modify.Apply) modify.Apply
- func WhenFileExists(file string, applies ...modify.Apply) modify.Apply
- func WhenFileNotContains(file, content string, applies ...modify.Apply) modify.Apply
- func WhenFileNotExists(file string, applies ...modify.Apply) modify.Apply
- func WhenNoFacades(facades []string, applies ...modify.Apply) modify.Apply
- func WrapNewline[T dst.Node](node T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCommand ¶ added in v1.17.0
AddCommand adds command to the foundation.Setup() chain in the Boot function.
func AddFilter ¶ added in v1.17.0
AddFilter adds filter to the foundation.Setup() chain in the Boot function.
func AddJob ¶ added in v1.17.0
AddJob adds job to the foundation.Setup() chain in the Boot function.
func AddMiddleware ¶ added in v1.17.0
AddMiddleware adds middleware to the foundation.Setup() chain in the Boot function.
func AddMigration ¶ added in v1.17.0
AddMigration adds migration to the foundation.Setup() chain in the Boot function.
func AddProvider ¶ added in v1.17.0
AddProvider adds service provider to the foundation.Setup() chain in the Boot function.
func AddRoute ¶ added in v1.17.0
AddRoute adds route to the foundation.Setup() chain in the Boot function. Add WithRouting(func()) to foundation.Setup() if not exists. Add pkg to this file imports, and add route to the function body in WithRouting. the pkg is the package path of the route file, e.g., "goravel/routes" the route will be like "routes.Web()"
func AddRule ¶ added in v1.17.0
AddRule adds rule to the foundation.Setup() chain in the Boot function.
func AddSeeder ¶ added in v1.17.0
AddSeeder adds seeder to the foundation.Setup() chain in the Boot function.
func ExprExists ¶
ExprExists checks if an expression exists in a slice of expressions. It uses structural equality comparison via ExprIndex.
Parameters:
- x: Slice of expressions to search in
- y: Expression to search for
Returns true if the expression exists in the slice, false otherwise.
Example:
exprs := []dst.Expr{
&dst.Ident{Name: "foo"},
&dst.Ident{Name: "bar"},
}
target := &dst.Ident{Name: "foo"}
if ExprExists(exprs, target) {
fmt.Println("Expression found")
}
func ExprIndex ¶
ExprIndex returns the index of the first occurrence of an expression in a slice. It uses structural equality comparison to match expressions.
Parameters:
- x: Slice of expressions to search in
- y: Expression to search for
Returns the index of the first occurrence, or -1 if not found.
Example:
exprs := []dst.Expr{
&dst.Ident{Name: "foo"},
&dst.Ident{Name: "bar"},
&dst.Ident{Name: "baz"},
}
target := &dst.Ident{Name: "bar"}
index := ExprIndex(exprs, target) // returns 1
func IsUsingImport ¶
IsUsingImport checks if an imported package is actually used in the file. It inspects the AST for selector expressions that reference the package.
Parameters:
- df: The parsed Go file to inspect
- path: Import path of the package (e.g., "github.com/goravel/framework/contracts/console")
- name: Optional package name. If not provided, uses the last segment of the path
Returns true if the package is used anywhere in the file, false otherwise.
Example:
file, _ := decorator.Parse(src)
// Check if "console" package from "github.com/goravel/framework/contracts/console" is used
if IsUsingImport(file, "github.com/goravel/framework/contracts/console") {
fmt.Println("console package is being used")
}
// Or specify a custom name
if IsUsingImport(file, "github.com/goravel/framework/contracts/console", "customName") {
fmt.Println("Package with alias 'customName' is being used")
}
func KeyExists ¶
KeyExists checks if a key exists in a slice of key-value expressions. It uses structural equality comparison via KeyIndex.
Parameters:
- kvs: Slice of expressions (expected to contain KeyValueExpr)
- key: Key expression to search for
Returns true if the key exists in any KeyValueExpr, false otherwise.
Example:
kvExprs := []dst.Expr{
&dst.KeyValueExpr{
Key: &dst.Ident{Name: "name"},
Value: &dst.BasicLit{Value: `"John"`},
},
&dst.KeyValueExpr{
Key: &dst.Ident{Name: "age"},
Value: &dst.BasicLit{Value: "30"},
},
}
targetKey := &dst.Ident{Name: "name"}
if KeyExists(kvExprs, targetKey) {
fmt.Println("Key found")
}
func KeyIndex ¶
KeyIndex returns the index of a key in a slice of key-value expressions. It searches for KeyValueExpr nodes and compares their keys using structural equality.
Parameters:
- kvs: Slice of expressions (expected to contain KeyValueExpr)
- key: Key expression to search for
Returns the index of the first KeyValueExpr with matching key, or -1 if not found.
Example:
kvExprs := []dst.Expr{
&dst.KeyValueExpr{
Key: &dst.Ident{Name: "name"},
Value: &dst.BasicLit{Value: `"John"`},
},
&dst.KeyValueExpr{
Key: &dst.Ident{Name: "age"},
Value: &dst.BasicLit{Value: "30"},
},
}
targetKey := &dst.Ident{Name: "age"}
index := KeyIndex(kvExprs, targetKey) // returns 1
func MustParseExpr ¶
MustParseExpr parses a Go expression from a string and returns its AST node. It wraps the expression in a minimal valid Go program to parse it, then extracts and returns the expression node with proper decorations and newlines.
Parameters:
- x: String representation of a Go expression
Returns the parsed expression as a dst.Node, with decorations preserved. Panics if the expression cannot be parsed.
Example:
// Parse a simple expression
node := MustParseExpr("&commands.ExampleCommand{}")
// Returns a UnaryExpr node representing the address-of operation
// Parse a composite literal
node := MustParseExpr(`map[string]interface{}{"key": "value"}`)
// Returns a CompositeLit node
// Parse a function call
node := MustParseExpr("fmt.Println(\"hello\")")
// Returns a CallExpr node
func RegisterMigration ¶ added in v1.17.0
func RegisterProvider ¶ added in v1.17.0
func RegisterRoute ¶ added in v1.17.0
func RemoveConfig ¶
RemoveConfig removes a configuration key from the config file.
func RemoveImport ¶
RemoveImport removes an import statement from the file.
func RemoveMigration ¶ added in v1.17.0
func RemoveProvider ¶ added in v1.17.0
RemoveProvider removes a service provider from the foundation.Setup() chain in the Boot function.
func RemoveRoute ¶ added in v1.17.0
RemoveRoute removes a route from the foundation.Setup() chain in the Boot function.
func ReplaceConfig ¶
ReplaceConfig replaces a configuration key with the given expression in the config file.
func Unregister ¶
Unregister remove a registration from the matched specified array.
func UnregisterMigration ¶ added in v1.17.0
func UnregisterProvider ¶ added in v1.17.0
func UnregisterRoute ¶ added in v1.17.0
func WhenDriver ¶ added in v1.17.0
func WhenFileContains ¶ added in v1.17.0
func WhenFileExists ¶ added in v1.17.0
func WhenFileNotContains ¶ added in v1.17.0
func WhenFileNotExists ¶ added in v1.17.0
func WrapNewline ¶
WrapNewline adds newline decorations to specific AST nodes for better formatting. It traverses the AST and adds Before/After newlines to KeyValueExpr, UnaryExpr, and FuncType result nodes to improve code readability.
Parameters:
- node: Any dst.Node to process
Returns the same node with newline decorations applied.
Example:
// Parse and wrap an expression
expr := MustParseExpr("&commands.ExampleCommand{}")
// The UnaryExpr will have newlines before and after
// For a composite literal with key-value pairs:
node := MustParseExpr(`map[string]int{"a": 1, "b": 2}`)
wrapped := WrapNewline(node)
// Each KeyValueExpr will have newlines for better formatting:
// map[string]int{
// "a": 1,
// "b": 2,
// }
Types ¶
This section is empty.