4 ms·
Whenever I see code like the example routing, I have to wonder if a hash lookup would be more appropriate. This is especially when all the functions called are
by imoverclocked 4y ago
Whenever I see code like the example routing, I have to wonder if a hash lookup would be more appropriate. This is especially when all the functions called are of exactly the same form, I immediately just want an interface for that and then define a map from “first” to handler.
The counter point in some languages (eg: Java) is that switch statements/expressions handle it this way under the hood at compile time depending on if it’s more efficient to use a map or a bunch of checks.
What is the actual best practice in go these days?
- hombre_fatal 4y agoWhen routing is static, it's trivial and any solution will work. Like when your routes are all static /foo/bar and they merely use ?query params to pass info. Not sure what you're asking, but handling dynamic segment routing ergonomically is where naive solutions tend to fail. For example, a simple trie/map router needs additional logic to backtrack and try downstream routes. You wouldn't want `GET /users/42/show` to 404 in the following route table. /users/42/admin /users/:id/show