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.