by tptacek · 6y ago · 0 comments
_ "google.golang.org/xds"
I was all “WTF how can that do anything?” but then a few minutes later he started wiring endpoint URIs into config files that began with xdi: and oh, of course. Still, is there, a bit of a code smell happening or is that just me?It's not a code smell; it's idiomatic Go; the search he wants is [import for side effects].
(The most common usage is importing database drivers).
I've written Go for a while, and it still feels a bit exotic, compared to its other control flow patterns.
Maybe "code smell" was the wrong word. But writing "surprising" logic in an `init()` function would definitely not be considered idiomatic.
It's admittedly a more exotic than the traditional alternative: importing a module, initializing some struct, passing it to some other module's struct-initialization.
Of course, now that I write it all out, and I imagine that I'd need to write all that just to give my gRPC service a load balancer... ok, I can accept the fancy hand-waves, give me the underscore import! :)
_ "google.golang.org/grpc/xds"