Another complete rework
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
"github.com/aws/aws-lambda-go/lambda"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
StatusCode int `json:"statusCode"`
|
||||
Headers map[string]string `json:"headers"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (Response, error) {
|
||||
log.Printf("Received request: %+v", request)
|
||||
|
||||
headers := map[string]string{
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Headers": "Content-Type",
|
||||
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
responseBody := map[string]interface{}{
|
||||
"message": "Hello from reorganized Go Lambda!",
|
||||
"path": request.Path,
|
||||
"method": request.HTTPMethod,
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(responseBody)
|
||||
|
||||
return Response{
|
||||
StatusCode: 200,
|
||||
Headers: headers,
|
||||
Body: string(body),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
lambda.Start(handler)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
module api-handler
|
||||
module go-functions
|
||||
|
||||
go 1.21
|
||||
|
||||
require github.com/aws/aws-lambda-go v1.41.0
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-lambda-go/lambda"
|
||||
)
|
||||
|
||||
type MyEvent struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type MyResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func HandleRequest(ctx context.Context, event MyEvent) (MyResponse, error) {
|
||||
return MyResponse{
|
||||
Message: fmt.Sprintf("Hello %s from Go Lambda!", event.Name),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
lambda.Start(HandleRequest)
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package crud
|
||||
|
||||
import "github.com/gjcampbell777/personal_site/backend-go/internal/database"
|
||||
|
||||
func Health(db *database.Client) map[string]string {
|
||||
return map[string]string{
|
||||
"status": "ok",
|
||||
"service": "portfolio-api",
|
||||
"database": db.Status(),
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package database
|
||||
|
||||
type Client struct{}
|
||||
|
||||
func NewClient() *Client {
|
||||
return &Client{}
|
||||
}
|
||||
|
||||
func (c *Client) Status() string {
|
||||
return "ready"
|
||||
}
|
||||
Reference in New Issue
Block a user