Skip to content

ServerOptions and ClientOptions use untyped dynamic options - #319

Merged
marioizquierdo merged 4 commits into
mainfrom
options_typeless_getters
Jun 11, 2021
Merged

marioizquierdo merged 4 commits into
mainfrom
options_typeless_getters

Conversation

@marioizquierdo

Copy link
Copy Markdown
Contributor

Fixes issue #316

Allow backwards compatibility when a new option is added

Every time a new server or client option is added, that would add a new property in the ServerOptions or ClientOptions struct, that is used from the generated code, forcing an upgrade on the runtime library even if the new option is not being used.

Now, the generated code will read options with the generic method ReadOpt, for example:

var pathPrefix string
ok := opts.ReadOpt("pathPrefix", &pathPrefix)

Example with a new option

If in the future a new option is added, let's say "foobar", the newly generated code will still work with older versions of the runtime:

// new generated code:
var foobar int
ok := opts.ReadOpt("foobar", &foobar)

This generated code will work with older versions of the runtime, that still don't know about the option. The method ReadOpt will just return false, which the same if the option was not set by the user.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@marioizquierdo
marioizquierdo merged commit ef48131 into main Jun 11, 2021
@marioizquierdo
marioizquierdo deleted the options_typeless_getters branch June 11, 2021 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址