Skip to content

ServerOptions and ClientOptions generic getters for generated code #316

@marioizquierdo

Description

@marioizquierdo

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.

Go Playground example: https://play.golang.org/p/61N1d-nyiIY

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions