Skip to content

Instantly share code, notes, and snippets.

@gmorse81
Created March 14, 2022 04:04
Show Gist options
  • Save gmorse81/61c8257d0ccf14cedef078ecf3685ac3 to your computer and use it in GitHub Desktop.
Save gmorse81/61c8257d0ccf14cedef078ecf3685ac3 to your computer and use it in GitHub Desktop.
Netlify deploy-succeeded function written in go
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