Last active
December 30, 2019 21:44
-
-
Save JNaeemGitonga/7e871a3584cbbbf3d83fec932f538ef4 to your computer and use it in GitHub Desktop.
func postStory(story string) (events.APIGatewayProxyResponse, error) {...}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func postStory(ctx context.Context, story string) (events.APIGatewayProxyResponse, error) { | |
err := client.Ping(ctx, readpref.Primary()) | |
if err != nil { | |
return handleError(err) | |
} | |
var raw Story // <--- this and the folowing two lines was a big gotcha | |
s := strings.NewReader(story) // ^---> because the type of response.Body is `string` and you need it | |
json.NewDecoder(s).Decode(&raw) // ^---> to be what's defined in your schema/json | |
result, err := collection.InsertOne(ctx, raw) | |
if err != nil { | |
return handleError(err) | |
} | |
/* | |
the following was a big gotcha, | |
cause `result` is type *InsertOneResult | |
and you can't send that as json in your lambda response | |
I had to do some reflection to the result in order to send it. | |
*/ | |
newDbResult = DbResults{nil, result} | |
return handleResultSendDbResponse("InsertOneResult") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment