Created
March 14, 2022 04:04
-
-
Save gmorse81/61c8257d0ccf14cedef078ecf3685ac3 to your computer and use it in GitHub Desktop.
Netlify deploy-succeeded function written in go
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "encoding/json" | |
| "fmt" | |
| "github.com/askcloudarchitech/mediumautopost/pkg/mediumautopost" | |
| "github.com/aws/aws-lambda-go/events" | |
| "github.com/aws/aws-lambda-go/lambda" | |
| ) | |
| type RequestBody struct { | |
| Payload Payload `json:"payload"` | |
| } | |
| type Payload struct { | |
| Context string `json:"context"` | |
| } | |
| func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) { | |
| requestBody := RequestBody{} | |
| json.Unmarshal([]byte(request.Body), &requestBody) | |
| if requestBody.Payload.Context == "production" { | |
| mediumautopost.Do("") | |
| } else { | |
| fmt.Println("context " + requestBody.Payload.Context + " detected, skipping") | |
| } | |
| return &events.APIGatewayProxyResponse{ | |
| StatusCode: 200, | |
| Body: "Success", | |
| IsBase64Encoded: false, | |
| }, nil | |
| } | |
| func main() { | |
| lambda.Start(handler) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment