add nano functions example?
kmarquardsen opened this issue · 3 comments
Is this possible/would it provide value?
functions:
create:
handler: todos/handler.Handler
events:
- http:
path: todos
method: post
cors: true
list:
handler: todos/handler.Handler
events:
- http:
path: todos
method: get
cors: true
get:
handler: todos/handler.Handler
events:
- http:
path: todos/{id}
method: get
cors: true
update:
handler: todos/handler.Handler
events:
- http:
path: todos/{id}
method: put
cors: true
delete:
handler: todos/handler.Handler
events:
- http:
path: todos/{id}
method: delete
cors: true
If you want to use a single handler.Handler then you would need to do a setup similar to https://github.com/yunspace/serverless-golang/blob/master/examples/aws-golang-net/serverless.yml#L11
I think I'm talking about the opposite of that?
@kmarquardsen the example above keeps referencing the same handler: todos/handler.Handler Go function by all those Lambda functions.
I think this is doable and reasonable, you just need to have some logic inside that handler function to determine which action to take depending on the HTTP medhod from the current request.
In my opinion I think having individual Go functions may be simpler/cleaner, because you don't need to have this logic and you just call those dedicated functions on a per method level. But it all depends on how much can you share between the various code paths of the common Go handler function.