The twirp runtime should expose generic getters to different types, returning default values when not present, so we don't have to force library updates every time clients or server options add a new option.
Current usage from generated code:
pathPrefix := opts.PathPrefix()
The problem with this approach is that older versions of the twirp.ServerOptionts type does not include the PathPrefix() method, which forces consumers of the generated client to update twirp to latest version, even if they don't care about the PathPrefix option.
The alternative would look like this:
var pathPrefix string
ok := opts.GetOpt("pathPrefix", &pathPrefix)
The new GetOpt method returns true if the key was set on the options, and false if it was not set, which works even if the option doesn't exist in the given version of the runtime library.
The twirp runtime should expose generic getters to different types, returning default values when not present, so we don't have to force library updates every time clients or server options add a new option.
Current usage from generated code:
The problem with this approach is that older versions of the
twirp.ServerOptionts
type does not include thePathPrefix()
method, which forces consumers of the generated client to update twirp to latest version, even if they don't care about the PathPrefix option.The alternative would look like this:
The new
GetOpt
method returns true if the key was set on the options, and false if it was not set, which works even if the option doesn't exist in the given version of the runtime library.Go Playground example: https://play.golang.org/p/61N1d-nyiIY