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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Naxi
  • 1,504
  • 5
  • 33
  • 72
  • 1
    this post might be useful: https://stackoverflow.com/questions/23542989/pointers-vs-values-in-parameters-and-return-values?rq=1 – andersryanc Nov 03 '20 at 05:01
  • 1
    that said, according to the [AWS Official Documentation](https://docs.aws.amazon.com/lambda/latest/dg/golang-handler.html) 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." – andersryanc Nov 03 '20 at 05:05

0 Answers0