Skip to content

Add optional configuration information to service handlers #70

@srstrong

Description

@srstrong

I have an issue where it would be nice to add an additional parameter to every service method with some configuration/state information provided when starting the service - so something along the lines of:

AdditionalOptions = ... %% some term
Server = #{grpc_opts => #{service_protos => [my_service], 
                                              services => #{'my.myService' => {my_service_handler, AdditionalOptions}}
                  ,...}
grpcbox:start_server(Server)

and then in my_service.erl:

my_service_function(Ctx, Input, AdditionalOptions) ->
 ...

or alternatively:

my_service_function(Ctx, Input) ->
  AdditionalOptions = ctx:get(Ctx, ctx_additional_options),
  ...

I guess the latter means that the generated behaviours don't need changing...

Any thoughts on a) whether this is a PR that you'd be interested in taking and b) if it is something you'd be interested in, views on what the usage should look like?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions