Conversation
…ariable and add related tests
…for /api/generate
…curity headers middleware
…g in GenerateHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces important improvements to input validation, error handling, and context management across all code generators. It also bumps the Go version and adds a new dependency. The most significant changes are the introduction of strict validation for project and module names, propagation of context for cancellation support, and corresponding updates to tests.
Input validation and error handling:
ValidateProjectNameandValidateModuleNamefunctions ingen_utils.goto enforce strict, safe naming conventions for generated projects and modules, preventing path traversal and other unsafe input. Added a customErrValidationerror type for clear error reporting.Generatemethods (gen_simple_project.go,gen_microservice.go,gen_cli_app.go,gen_ai_agent.go) to validateNameandModuleNameat the start, defaulting to a safe name if empty, and returning errors early if validation fails. [1] [2] [3] [4]Context propagation and cancellation:
Generatemethods to accept acontext.Contextparameter and check for cancellation at key points, allowing for graceful interruption of long-running operations. [1] [2] [3] [4]cmd/goini/new.goto passcmd.Context()to the generator, ensuring context propagation from the command layer.Dependency and compatibility updates:
golang.org/x/timeas a new dependency ingo.mod.Test updates:
generators_test.goto use the newGenerate(context.Context, ...)signature, passingcontext.Background()as appropriate. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]These changes make the generators more robust, secure, and responsive to user cancellation, while improving overall code safety and maintainability.