Not sure i understand the use-case (why is it easier to put the functions
into a dict than onto a class?)
nameko expects services to be classes, so any programmatic approach would
be similar to what you've got (you could also create the whole class
dynamically) which seems fine
Best,
David
···
On Monday, 28 November 2016 11:10:53 UTC, adwhit wrote:
Hi, thanks for making a great library.
Question: Is there a way to programmatically add endpoints to services?
e.g. suppose I have a large dict of (endpoint, function) pairs
def myf1():
return "foo"
def myf2():
return "bar"
d = {
"f1": f1
"f2": f2
}
I would like to register these functions with a service programmatically
in a way that is functionally equivalent to:
The use case is that there are a largeish number of different functions
defined in various parts of the codebase, which are collected together in a
"Registry" object along with metadata. It would be nice to add endpoints
using this registry rather than typing them out again (DRY etc).
E.g. using Flask I would iterate over the registry and use app.add_url_rule
for each entry.
The above method is pretty hacky but seems to work fine so I'll probably
just use that.
Thanks,
Alex
···
On Monday, 28 November 2016 15:36:12 UTC, David Szotten wrote:
Hi Alex,
Not sure i understand the use-case (why is it easier to put the functions
into a dict than onto a class?)
nameko expects services to be classes, so any programmatic approach would
be similar to what you've got (you could also create the whole class
dynamically) which seems fine
Best,
David
On Monday, 28 November 2016 11:10:53 UTC, adwhit wrote:
Hi, thanks for making a great library.
Question: Is there a way to programmatically add endpoints to services?
e.g. suppose I have a large dict of (endpoint, function) pairs
def myf1():
return "foo"
def myf2():
return "bar"
d = {
"f1": f1
"f2": f2
}
I would like to register these functions with a service programmatically
in a way that is functionally equivalent to: