/*
handleResultSendDbResponse is used to handle multiple db responses
from insert and update operations it can also be extended to handle
delete operations when we are ready to add that functionality to the
API
*/
func handleResultSendDbResponse(whichType string) (events.APIGatewayProxyResponse, error) {
/*
you have to use reflect to dynamically get a value from a struct as
I am doing below. I used a struct so that I could reuse some code
I went through this just so I could access a property using a variable that
stored the prop name. In JS I could have done Story[whichType]
*/
reflectValue := reflect.ValueOf(&newDbResult)
underlyingStruct := reflect.Indirect(reflectValue).FieldByName(whichType).Elem()
reflectVal := underlyingStruct.Interface()
str := fmt.Sprintf("%+v", reflectVal)
return events.APIGatewayProxyResponse{
Body: str,
StatusCode: 200,
}, nil
}
view raw pt-8.main.go hosted with ❤ by GitHub