mrserverless / serverless-golang

AWS Lambda Go functions using Serverless Framework and Python shim
Other
302 stars 21 forks source link

add nano functions example? #19

Closed kmarquardsen closed 7 years ago

kmarquardsen commented 7 years ago

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
mrserverless commented 7 years ago

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

kmarquardsen commented 7 years ago

I think I'm talking about the opposite of that?

cristim commented 7 years ago

@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.