Package functiondefinitions
Overview ▹
Index ▹
func ExtractFunctionDefinitionsFromPackage ¶
func ExtractFunctionDefinitionsFromPackage(content string, category string) error
ExtractFunctionDefinitionsFromPackage parses the given file for public functions and populates internalstates.AvailableFunctions. The function definitions are stored in the internalstates.AvailableFunctions map. The key is the function name and the value is a FunctionDefinition struct. The FunctionDefinition struct contains the function's name, description, package, inputs, and outputs. The inputs and outputs are stored as FunctionInput and FunctionOutput structs, respectively. The FunctionInput and FunctionOutput structs contain the name, type, and GoType of the input/output. The GoType is the Go type of the input/output, while the Type is a simplified type string (e.g., "string", "number", "boolean", "json").
The function returns an error if the file cannot be parsed.
Parameters:
- packagePath: the path to the package file to parse.
Returns:
- error: an error if the file cannot be parsed.
func displayNameOrDefault ¶
func displayNameOrDefault(displayName, defaultName string) string
displayNameOrDefault returns the displayName if it is not empty, otherwise it returns the defaultName.
Parameters:
- displayName: the display name to check.
- defaultName: the default name to use if the display name is empty.
Returns:
- string: the display name if it is not empty, otherwise the default name.
func extractTagValue ¶
func extractTagValue(docText, tag string) string
extractTagValue extracts the value of a tag from a docstring. The tag value is expected to be in the format "- tag: value".
Parameters:
- docText: the docstring text to extract the tag value from.
- tag: the tag to extract the value of.
Returns:
- string: the value of the tag, or an empty string if the tag is not found.
func typeExprToSimpleType ¶
func typeExprToSimpleType(expr ast.Expr) string
typeExprToSimpleType translates an ast.Expr (which represents a type in Go's AST) into a simple type string, treating user-defined types and any complex structures as "json". The simple types are "string", "number", "boolean", and "json". This function is used to simplify the type representation for function inputs and outputs.
The function returns a simple type string.
Parameters:
- expr: the ast.Expr representing the type.
Returns:
- string: the simple type string.
func typeExprToString ¶
func typeExprToString(expr ast.Expr) string
typeExprToString converts an ast.Expr that represents a type into a string representation. This function aims to produce more readable type strings for complex types.
The function returns a string representation of the type.
Parameters:
- expr: the ast.Expr representing the type.
Returns:
- string: the string representation of the type.