-
-
Notifications
You must be signed in to change notification settings - Fork 1k
docs(std-http-server): warn when not using Go 1.22 #1967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1adcd35 to
bfcdd6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a mechanism to warn users when the target module's Go version is below 1.22 for the std-http-server generation, helping avoid runtime issues such as unexpected 404 responses. Key changes include:
- Adding functions to locate and parse go.mod/tools.mod files and verify the Go version.
- Implementing warning generation in GenerateOptions and integrating warning output in the CLI.
- Updating the main command to display warnings when present.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/codegen/minimum_go_version.go | Introduces functions to search for and parse go.mod/tools.mod and checks for minimum Go version. |
| pkg/codegen/configuration.go | Adds warnings functionality for std-http-server generation based on the Go version in the module file. |
| cmd/oapi-codegen/oapi-codegen.go | Integrates warning output by printing any warnings returned from GenerateOptions into stderr. |
Files not reviewed (1)
- go.mod: Language not supported
| } | ||
|
|
||
| parentDir := filepath.Dir(currentDir) | ||
| if parentDir == "/" { |
Copilot
AI
May 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On non-Unix systems, using a hard-coded "/" as the root directory may lead to improper behavior; consider using a cross-platform approach to determine when to stop recursing upward.
| if parentDir == "/" { | |
| if parentDir == currentDir { |
Although this is less necessary after bumping our minimum Go version to 1.22 (in 0e8156a), it's still worthwhile ensuring that the module we're generating the code for is correctly set to Go 1.22, otherwise users will receive: HTTP/1.1 404 Not Found ... 404 page not found To do this, we can introduce a new means to flag "warnings" that need to be output. We need to make sure we're using `ParseLax` to reduce the risk of new directives or content being introduced into a `go.mod` breaking `oapi-codegen`. This is a step towards being able to implement future warnings to ensure that consumers are using correct Go versions. Closes #1628. [0]: https://www.jvt.me/posts/2024/03/04/go-net-http-why-404/
Although this is less necessary after bumping our minimum Go version to
1.22 (in 0e8156a), it's still
worthwhile ensuring that the module we're generating the code for is
correctly set to Go 1.22, otherwise users will receive:
To do this, we can introduce a new means to flag "warnings" that need to
be output.
We need to make sure we're using
ParseLaxto reduce the risk of newdirectives or content being introduced into a
go.modbreakingoapi-codegen.This is a step towards being able to implement future warnings to ensure
that consumers are using correct Go versions.
Closes #1628.
Warning
I'm not quite sure about this - especially for
oapi-codegen-as-a-library