From 76a323ec00d0cde2c46c93d35a486f2acc581a62 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 19:03:09 +0800
Subject: [PATCH 01/20] initial commit
---
go.mod | 2 ++
go.sum | 21 ++++++++++++++++++++
handler.go | 53 ++++++++++++++++++++++++++++++-------------------
makefile | 30 +++++-----------------------
method/hello.go | 4 ----
netlify.toml | 7 +++++++
6 files changed, 68 insertions(+), 49 deletions(-)
create mode 100644 go.sum
create mode 100644 netlify.toml
diff --git a/go.mod b/go.mod
index d6a6b2e..dea9444 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
module github.com/TechProber/pro-bot
go 1.17
+
+require github.com/aws/aws-lambda-go v1.28.0
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..4f6d652
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,21 @@
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/aws/aws-lambda-go v1.28.0 h1:fZiik1PZqW2IyAN4rj+Y0UBaO1IDFlsNo9Zz/XnArK4=
+github.com/aws/aws-lambda-go v1.28.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/handler.go b/handler.go
index e924c1b..5ea88fc 100644
--- a/handler.go
+++ b/handler.go
@@ -1,34 +1,47 @@
package main
import (
- "encoding/json"
- "log"
+ // "encoding/json"
+ // "log"
"net/http"
- "strings"
+ // "strings"
- "github.com/TechProber/pro-bot/method"
- "github.com/TechProber/pro-bot/model"
+ // "github.com/TechProber/pro-bot/method"
+ // "github.com/TechProber/pro-bot/model"
+ "github.com/aws/aws-lambda-go/events"
+ "github.com/aws/aws-lambda-go/lambda"
)
-func Handler(res http.ResponseWriter, req *http.Request) {
- body := &model.WebhookReqBody{} // decode the JSON response body
- if err := json.NewDecoder(req.Body).Decode(body); err != nil {
- log.Println("could not decode request body", err)
- return
- }
+// func handler(res http.ResponseWriter, req *http.Request) {
- if !strings.Contains(strings.ToLower(body.Message.Text), "morning") {
- return
- }
+// body := &model.WebhookReqBody{} // decode the JSON response body
+// if err := json.NewDecoder(req.Body).Decode(body); err != nil {
+// log.Println("could not decode request body", err)
+// return
+// }
- if err := method.Hello(body.Message.Chat.ID, body.Message.Text); err != nil {
- log.Println("error in sending reply:", err)
- return
- }
+// if !strings.Contains(strings.ToLower(body.Message.Text), "morning") {
+// return
+// }
- log.Println("reply sent")
+// if err := method.Hello(body.Message.Chat.ID, body.Message.Text); err != nil {
+// log.Println("error in sending reply:", err)
+// return
+// }
+
+// log.Println("reply sent")
+// }
+func handler(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
+ return &events.APIGatewayProxyResponse{
+ StatusCode: 200,
+ Headers: map[string]string{"Content-Type": "text/plain"},
+ MultiValueHeaders: http.Header{"Set-Cookie": {"Ding", "Ping"}},
+ Body: "Hello, World!",
+ IsBase64Encoded: false,
+ }, nil
}
func main() {
- http.ListenAndServe(":3000", http.HandlerFunc(Handler))
+ // http.ListenAndServe(":3000", http.HandlerFunc(handler))
+ lambda.Start(handler)
}
diff --git a/makefile b/makefile
index dc0427f..d535f5c 100644
--- a/makefile
+++ b/makefile
@@ -3,6 +3,7 @@
TELEGRAM_TOKEN := $(TELEGRAM_TOKEN)
URL := "https://7260-206-190-232-194.ngrok.io"
GHCR_URL := ghcr.io
+APP_NAME := pro-bot
GHCR_USERNAME := TechProber
VERSION := latest
@@ -17,31 +18,11 @@ set-webhook:
@echo "==> Update webhook endpoint"
@curl -F "url=$(URL)" https://api.telegram.org/bot$(TELEGRAM_TOKEN)/setWebhook
-ghcr-login:
- @echo "==> Login to GHCR"
- @echo $(GHCR_TOKEN) | docker login $(GHCR_URL) -u $(GHCR_USERNAME) --password-stdin
-
.PHONY: build
build:
- @echo "==> Build application image with tag $(IMAGE_TAG)"
- @DOCKER_BUILDKIT=1 docker build \
- --platform=linux/amd64 \
- -t $(IMAGE_NAME):$(IMAGE_TAG) \
- .
-
-.PHONY: nerd-build
-nerd-build:
- @echo "==> Build application image with tag $(IMAGE_TAG)"
- @sudo nerdctl build \
- --platform=linux/amd64 \
- -t $(IMAGE_NAME):$(IMAGE_TAG) \
- .
-
-.PHONY: tag
-tag:
- @echo "==> Tag the local image as GHCR image"
- @docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(GHCR_URL):$(IMAGE_TAG)
- @docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(GHCR_URL):latest
+ @mkdir -p functions
+ @go get ./...
+ @go build -o functions/$(APP_NAME) ./...
.PHONY: help
help:
@@ -55,10 +36,9 @@ Usage: $ make [TARGETS]
TARGETS
help Show the help menu
- build Build the application image
+ build Build the application artifact
run Run the application container locally (VERSION optional)
set-webhook Update the bound webhook url
- publish Build the application image, tag it with a custom version tag, and push it to GHCR (Version required)
EXAMPLE USAGE
diff --git a/method/hello.go b/method/hello.go
index 8f81df3..2a13240 100644
--- a/method/hello.go
+++ b/method/hello.go
@@ -12,10 +12,6 @@ import (
func Hello(chatID int64, message string) error {
log.Println(message)
- // reqBody := &model.MessageReqBody{
- // ChatID: chatID,
- // Text: "Nihao!!",
- // }
reqBody := &model.StickerReqBody{
ChatID: chatID,
Sticker: model.GoodMorningStickerRef,
diff --git a/netlify.toml b/netlify.toml
new file mode 100644
index 0000000..b626ead
--- /dev/null
+++ b/netlify.toml
@@ -0,0 +1,7 @@
+[build]
+ command = "make build"
+ functions = "functions"
+ publish = "site"
+[build.environment]
+ # Change this path with the path to your repository
+ GO_IMPORT_PATH = "github.com/TechProber/pro-bot"
From abf1d286c6cef843b6f47dc5db310c44c847bc31 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:09:37 +0800
Subject: [PATCH 02/20] (fix): fixed command
---
makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/makefile b/makefile
index d535f5c..79e41c2 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ set-webhook:
build:
@mkdir -p functions
@go get ./...
- @go build -o functions/$(APP_NAME) ./...
+ @go build -o functions/$(APP_NAME) .
.PHONY: help
help:
From d5d38fb5b746417d2dfb25db1527fdc10e9c4da1 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:15:44 +0800
Subject: [PATCH 03/20] updated syntax
---
makefile | 2 +-
netlify.toml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/makefile b/makefile
index 79e41c2..270b75c 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ set-webhook:
build:
@mkdir -p functions
@go get ./...
- @go build -o functions/$(APP_NAME) .
+ @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/$(APP_NAME) .
.PHONY: help
help:
diff --git a/netlify.toml b/netlify.toml
index b626ead..8a19420 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,7 +1,7 @@
[build]
command = "make build"
functions = "functions"
- publish = "site"
+ publish = "pro-bot"
[build.environment]
# Change this path with the path to your repository
GO_IMPORT_PATH = "github.com/TechProber/pro-bot"
From 43e1352527c37164501ba198527a58f815a8ad82 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:16:34 +0800
Subject: [PATCH 04/20] updated syntax
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 8a19420..6eecca3 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,7 +1,7 @@
[build]
command = "make build"
functions = "functions"
- publish = "pro-bot"
+ publish = "functions"
[build.environment]
# Change this path with the path to your repository
GO_IMPORT_PATH = "github.com/TechProber/pro-bot"
From efffe7301277aa9d23294151016807a4ad8b7160 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:25:30 +0800
Subject: [PATCH 05/20] applied changes for test
---
{method => function/hello}/hello.go | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename {method => function/hello}/hello.go (100%)
diff --git a/method/hello.go b/function/hello/hello.go
similarity index 100%
rename from method/hello.go
rename to function/hello/hello.go
From 0e1a0e2147ae400ecd7619b9b9e3335eb083bf62 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:26:05 +0800
Subject: [PATCH 06/20] applied fix
---
netlify.toml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/netlify.toml b/netlify.toml
index 6eecca3..60addc2 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,7 +1,7 @@
[build]
command = "make build"
- functions = "functions"
- publish = "functions"
+ functions = "function"
+ publish = "function"
[build.environment]
# Change this path with the path to your repository
GO_IMPORT_PATH = "github.com/TechProber/pro-bot"
From a19817b84897b1e0220f6a654e46c0ce878b2d41 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:28:02 +0800
Subject: [PATCH 07/20] applied fix
---
{function => functions}/hello/hello.go | 0
netlify.toml | 4 ++--
2 files changed, 2 insertions(+), 2 deletions(-)
rename {function => functions}/hello/hello.go (100%)
diff --git a/function/hello/hello.go b/functions/hello/hello.go
similarity index 100%
rename from function/hello/hello.go
rename to functions/hello/hello.go
diff --git a/netlify.toml b/netlify.toml
index 60addc2..6eecca3 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,7 +1,7 @@
[build]
command = "make build"
- functions = "function"
- publish = "function"
+ functions = "functions"
+ publish = "functions"
[build.environment]
# Change this path with the path to your repository
GO_IMPORT_PATH = "github.com/TechProber/pro-bot"
From 9a1ac21229644e90146f582433c1ea8636805a93 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:33:58 +0800
Subject: [PATCH 08/20] applied fix
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 6eecca3..5c4ee0a 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,6 +1,6 @@
[build]
command = "make build"
- functions = "functions"
+ functions = "hello"
publish = "functions"
[build.environment]
# Change this path with the path to your repository
From ed73da30194d04afc9b9128538d1e8d3a10f9819 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:35:07 +0800
Subject: [PATCH 09/20] applied fix
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index 5c4ee0a..6eecca3 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,6 +1,6 @@
[build]
command = "make build"
- functions = "hello"
+ functions = "functions"
publish = "functions"
[build.environment]
# Change this path with the path to your repository
From 8ac8a7d9533821a5f31022b1fb0fd864dabe3a1f Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:37:22 +0800
Subject: [PATCH 10/20] removed netlify.toml
---
netlify.toml | 7 -------
1 file changed, 7 deletions(-)
delete mode 100644 netlify.toml
diff --git a/netlify.toml b/netlify.toml
deleted file mode 100644
index 6eecca3..0000000
--- a/netlify.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[build]
- command = "make build"
- functions = "functions"
- publish = "functions"
-[build.environment]
- # Change this path with the path to your repository
- GO_IMPORT_PATH = "github.com/TechProber/pro-bot"
From 2f051ec0f642b6e347ff6b1be2e33ca9753c0659 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:41:34 +0800
Subject: [PATCH 11/20] applied fix
---
functions/hello/hello.go | 38 --------------------------------------
makefile | 2 +-
netlify.toml | 7 +++++++
3 files changed, 8 insertions(+), 39 deletions(-)
delete mode 100644 functions/hello/hello.go
create mode 100644 netlify.toml
diff --git a/functions/hello/hello.go b/functions/hello/hello.go
deleted file mode 100644
index 2a13240..0000000
--- a/functions/hello/hello.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package method
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "log"
- "net/http"
-
- "github.com/TechProber/pro-bot/model"
-)
-
-func Hello(chatID int64, message string) error {
- log.Println(message)
- reqBody := &model.StickerReqBody{
- ChatID: chatID,
- Sticker: model.GoodMorningStickerRef,
- }
-
- reqBytes, err := json.Marshal(reqBody)
- if err != nil {
- return err
- }
-
- res, err := http.Post(
- model.TelegramApi,
- "application/json",
- bytes.NewBuffer(reqBytes),
- )
- if err != nil {
- return err
- }
- if res.StatusCode != http.StatusOK {
- return errors.New("unexpected status" + res.Status)
- }
-
- return nil
-}
diff --git a/makefile b/makefile
index 270b75c..2592260 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ set-webhook:
build:
@mkdir -p functions
@go get ./...
- @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/$(APP_NAME) .
+ @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/app .
.PHONY: help
help:
diff --git a/netlify.toml b/netlify.toml
new file mode 100644
index 0000000..e9202a4
--- /dev/null
+++ b/netlify.toml
@@ -0,0 +1,7 @@
+[build]
+ command = "make build"
+ functions = "functions"
+ publish = "app"
+[build.environment]
+ # Change this path with the path to your repository
+ GO_IMPORT_PATH = "github.com/netlify/aws-lambda-go-example"
From d357a924e246a40232c46b21b3702f23b65b6b46 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:44:36 +0800
Subject: [PATCH 12/20] applied fix
---
makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/makefile b/makefile
index 2592260..c4d82de 100644
--- a/makefile
+++ b/makefile
@@ -20,9 +20,9 @@ set-webhook:
.PHONY: build
build:
- @mkdir -p functions
+ @mkdir -p functions/app
@go get ./...
- @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/app .
+ @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/app/app .
.PHONY: help
help:
From 9d8197fe63871f9a9907d199a194fdc9a372fe55 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:45:41 +0800
Subject: [PATCH 13/20] test
---
netlify.toml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/netlify.toml b/netlify.toml
index e9202a4..d31b963 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,7 +1,7 @@
[build]
command = "make build"
functions = "functions"
- publish = "app"
+ publish = "functions"
[build.environment]
# Change this path with the path to your repository
GO_IMPORT_PATH = "github.com/netlify/aws-lambda-go-example"
From cba3d05fb7ffe97a30c3a1cc476f30f56586ec87 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:51:29 +0800
Subject: [PATCH 14/20] applied test
---
makefile | 2 +-
netlify.toml | 5 +----
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/makefile b/makefile
index c4d82de..5760908 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ set-webhook:
build:
@mkdir -p functions/app
@go get ./...
- @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/app/app .
+ @GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/app ./handler.go
.PHONY: help
help:
diff --git a/netlify.toml b/netlify.toml
index d31b963..e387652 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,7 +1,4 @@
[build]
command = "make build"
functions = "functions"
- publish = "functions"
-[build.environment]
- # Change this path with the path to your repository
- GO_IMPORT_PATH = "github.com/netlify/aws-lambda-go-example"
+ publish = "./"
From dd57100d08e2dbc856fd00297529def4bc753a34 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 21:54:09 +0800
Subject: [PATCH 15/20] applied fix
---
makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/makefile b/makefile
index 5760908..c3037f4 100644
--- a/makefile
+++ b/makefile
@@ -20,7 +20,7 @@ set-webhook:
.PHONY: build
build:
- @mkdir -p functions/app
+ @mkdir -p functions
@go get ./...
@GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o functions/app ./handler.go
From 35874b09e39ff55e30380d273ea4e824d77ac5b5 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 22:00:04 +0800
Subject: [PATCH 16/20] added site reference
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index ab895ad..e4ab8dc 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,7 @@ Special thanks go to all [ contributors ](https://github.com/TechProber/pro-bot/
- [https://stackoverflow.com/questions/52765833/why-i-cant-send-sticker-by-its-id](https://stackoverflow.com/questions/52765833/why-i-cant-send-sticker-by-its-id)
- [Telegram, getting file_id for existing sticker](https://stackoverflow.com/questions/34355648/telegram-getting-file-id-for-existing-sticker)
- [How to set up push notifications in your Telegram bot](https://www.freecodecamp.org/news/telegram-push-notifications-58477e71b2c2/)
+- [https://lornajane.net/posts/2020/a-first-netlify-function-in-golang](https://lornajane.net/posts/2020/a-first-netlify-function-in-golang)
## Development Notes
@@ -78,6 +79,7 @@ POST `https://api.telegram.org/bot/sendMessage?chat_id=&text=/sendMessage?chat_id=&text=
```
+
### Send Sticker
POST `https://api.telegram.org/bot/sendSticker?chat_id=&sticker=`
From cbade243ae66d14b4cfbb34936deb5eb29627207 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 22:06:37 +0800
Subject: [PATCH 17/20] added CI badge
---
README.md | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index e4ab8dc..f930250 100644
--- a/README.md
+++ b/README.md
@@ -6,12 +6,14 @@
-
+
+
+
-
+
-
+
@@ -22,6 +24,9 @@
+
+
+
## Introduction
From 566426c8a9a6fcfccbac90b88f9fbc0eb6eef3b9 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 22:14:32 +0800
Subject: [PATCH 18/20] updated handler logics
---
handler.go | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/handler.go b/handler.go
index 5ea88fc..47c0d78 100644
--- a/handler.go
+++ b/handler.go
@@ -3,11 +3,13 @@ package main
import (
// "encoding/json"
// "log"
- "net/http"
+
// "strings"
// "github.com/TechProber/pro-bot/method"
// "github.com/TechProber/pro-bot/model"
+ "context"
+
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
@@ -31,14 +33,19 @@ import (
// log.Println("reply sent")
// }
-func handler(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
+func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
+ params := request.QueryStringParameters
+
+ name := "World"
+ if params["name"] != "" {
+ name = params["name"]
+ }
+
return &events.APIGatewayProxyResponse{
- StatusCode: 200,
- Headers: map[string]string{"Content-Type": "text/plain"},
- MultiValueHeaders: http.Header{"Set-Cookie": {"Ding", "Ping"}},
- Body: "Hello, World!",
- IsBase64Encoded: false,
+ StatusCode: 200,
+ Body: "Hi " + name,
}, nil
+
}
func main() {
From 5e50cf61f3e5af92a72c08000e518fc8baad9a3f Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 22:21:55 +0800
Subject: [PATCH 19/20] updated handler logics
---
handler.go | 2 ++
1 file changed, 2 insertions(+)
diff --git a/handler.go b/handler.go
index 47c0d78..bce65f9 100644
--- a/handler.go
+++ b/handler.go
@@ -9,6 +9,7 @@ import (
// "github.com/TechProber/pro-bot/method"
// "github.com/TechProber/pro-bot/model"
"context"
+ "log"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@@ -35,6 +36,7 @@ import (
// }
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
params := request.QueryStringParameters
+ log.Println(request.HTTPMethod, request.Path)
name := "World"
if params["name"] != "" {
From 3b5fde9ec1d331f85d2ddb1de7e5131462cc3d70 Mon Sep 17 00:00:00 2001
From: yqlbu
Date: Mon, 24 Jan 2022 22:23:50 +0800
Subject: [PATCH 20/20] updated logics
---
handler.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/handler.go b/handler.go
index bce65f9..4ca6041 100644
--- a/handler.go
+++ b/handler.go
@@ -9,7 +9,7 @@ import (
// "github.com/TechProber/pro-bot/method"
// "github.com/TechProber/pro-bot/model"
"context"
- "log"
+ "fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@@ -36,7 +36,7 @@ import (
// }
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
params := request.QueryStringParameters
- log.Println(request.HTTPMethod, request.Path)
+ fmt.Println(request.HTTPMethod, request.Path)
name := "World"
if params["name"] != "" {