-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[GO] Go Server: Adds ordered routes to go-server router #21280
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
base: master
Are you sure you want to change the base?
[GO] Go Server: Adds ordered routes to go-server router #21280
Conversation
@@ -21,8 +21,9 @@ import ( | |||
|
|||
// A Route defines the parameters for an api endpoint | |||
type Route struct { | |||
Method string | |||
Pattern string | |||
Name string |
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.
thanks for the PR
is adding Name
a breaking change to the existing users using the auto-generated go server code?
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.
From my understanding, this would only be a breaking change if someone constructed one using an unkeyed literal, so like Route{"pattern","etc"}
, which in my experience is pretty rare to see in Go as the vast majority of folks used keyed literals (like Route{ Pattern: "pattern", ...}
)
In fact, even the Go language backwards compatibility documentation specifically calls this out and seems to indicate that only keyed structs will be ensured to be backwards compatible:
Struct literals. For the addition of features in later point releases, it may be necessary to add fields to exported structs in the API. Code that uses unkeyed struct literals (such as pkg.T{3, "x"}) to create values of these types would fail to compile after such a change. However, code that uses keyed literals (pkg.T{A: 3, B: "x"}) will continue to compile after such a change. We will update such data structures in a way that allows keyed struct literals to remain compatible, although unkeyed literals may fail to compile. (There are also more intricate cases involving nested data structures or interfaces, but they have the same resolution.) We therefore recommend that composite literals whose type is defined in a separate package should use the keyed notation.
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.
There are a few situations where if people are using bits and pieces of generated code, but not all of it, it could be considered a breaking change, but I am not sure where y'all draw the official line for this repo (e.g. any mustache template change could be considered a breaking change if users are overriding one with their own version)
can you please review the test failure when you've time? |
@wing328 I fixed the test, thanks for the heads up on that! |
Go maps are never deterministically ordered, according to the Go map documentation.
In the past, I think it was close enough to not be a problem, but since Go 1.24's refactor of how Go maps work (they are using swiss tables now) the orders are nearly random. This results in the returned
Routes
map being in a different iteration order each time, which is not ideal for cases where router-order matters (#19445 for instance)To solve this, I have added a new function called
OrderedRoutes
which returns routes in an order-deterministic slice instead. I left the oldRoutes()
getter for the time being for backwards compat.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)