0

I was looking into a piece of code of creating a simple lambda function with go which returns a dummy value when invoked.

package main

import (
    "github.com/aws/aws-lambda-go/lambda"
)

type book struct {
    ISBN   string `json:"isbn"`
    Title  string `json:"title"`
    Author string `json:"author"`
}

func show() (*book, error) {
    bk := &book{
        ISBN:   "978-1420931693",
        Title:  "The Republic",
        Author: "Plato",
    }

    return bk, nil
}

func main() {
    lambda.Start(show)
}

In the above piece of code, the only thing I am not able to understand is why we are returning a pointer from the show() function and how is this resolved. What happens if we return the actual book variable instead of it's pointer.

2
  • 1
    this post might be useful: stackoverflow.com/questions/23542989/… Commented Nov 3, 2020 at 5:01
  • 1
    that said, according to the AWS Official Documentation for writing lambda handlers in go, they don't use a pointer... and your TOut should "represent types compatible with the encoding/json standard library." Commented Nov 3, 2020 at 5:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.