diff --git a/.github/workflows/lambdago.yml b/.github/workflows/lambdago.yml index 2191444..635da35 100644 --- a/.github/workflows/lambdago.yml +++ b/.github/workflows/lambdago.yml @@ -41,4 +41,4 @@ jobs: aws-region: us-east-1 - name: Upload Zip - run: aws lambda update-function-code --function-name gohtmx --zip-file fileb://main.zip + run: aws lambda update-function-code --function-name gohtmx --zip-file fileb://bin/main.zip diff --git a/Makefile b/Makefile index 04d61f6..82e3885 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,63 @@ -.PHONY: build run +# Both native and cross architecture builds are supported. +# The target architecture is select by setting the ARCH variable. +# When ARCH is undefined it is set to the detected host architecture. +# When ARCH differs from the host architecture a crossbuild will be performed. +ARCHES = amd64 arm64 ppc64le s390x + +# BUILDARCH is the host architecture +# ARCH is the target architecture +# we need to keep track of them separately +BUILDARCH ?= $(shell uname -m) + +# canonicalized names for host architecture +ifeq ($(BUILDARCH),aarch64) + BUILDARCH=arm64 +endif +ifeq ($(BUILDARCH),x86_64) + BUILDARCH=amd64 +endif + +# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling +ARCH ?= $(BUILDARCH) + +# canonicalized names for target architecture +ifeq ($(ARCH),aarch64) + override ARCH=arm64 +endif +ifeq ($(ARCH),x86_64) + override ARCH=amd64 +endif + build: - @echo "Building Go application..." - @cd src && go build -o main + @echo "Building Go application..." + cd src && GOOS=linux GOARCH=$(ARCH) go build -o ../bin/main main.go + +zip: + cd bin && zip -j main.zip main + + +run: + go run main.go + +test: + @echo "No Testing Go application..." + +compile: + echo "Compiling for every OS and Platform" + GOOS=linux GOARCH=arm go build -o bin/main-linux-arm main.go + GOOS=linux GOARCH=arm64 go build -o bin/main-linux-arm64 main.go + GOOS=freebsd GOARCH=386 go build -o bin/main-freebsd-386 main.go + +clean: + rm -rf bin/* + +# .PHONY: build run +# build: +# @echo "Building Go application..." +# @cd src && go build -o main + +# run: build +# @echo "Running Go application..." +# @./src/main -run: build - @echo "Running Go application..." - @./src/main \ No newline at end of file diff --git a/bin/main b/bin/main new file mode 100755 index 0000000..37c400c Binary files /dev/null and b/bin/main differ diff --git a/src/go.mod b/src/go.mod index 8b53b8a..efa427c 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,3 +1,5 @@ module github.com/alexanderfanz/go-htmx-template/src go 1.21.4 + +require github.com/aws/aws-lambda-go v1.41.0 // indirect diff --git a/src/go.sum b/src/go.sum new file mode 100644 index 0000000..5954d79 --- /dev/null +++ b/src/go.sum @@ -0,0 +1,2 @@ +github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y= +github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= diff --git a/src/main.go b/src/main.go index 06d9e4f..957ab26 100644 --- a/src/main.go +++ b/src/main.go @@ -1,10 +1,26 @@ - package main import ( + "context" + "fmt" "log" + + "github.com/aws/aws-lambda-go/lambda" ) +type MyEvent struct { + Name string `json:"name"` +} + +func lambdaHandler(ctx context.Context, event *MyEvent) (*string, error) { + log.Printf("Received event: %v", event) + if event == nil { + return nil, fmt.Errorf("received nil event") + } + message := fmt.Sprintf("Hello %s!", event.Name) + return &message, nil +} + func main() { - log.Println("Starting from main") + lambda.Start(lambdaHandler) }