From 80ff4767f4a772d5782a15599857641a93bc647c Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Thu, 27 Jun 2024 16:16:12 +0200 Subject: [PATCH] Remove old tools (#15) Signed-off-by: Matthias Wessendorf --- hack/install.sh | 2 - tools/knative-text-responder/.funcignore | 5 -- tools/knative-text-responder/.gitignore | 5 -- tools/knative-text-responder/README.md | 23 ------- tools/knative-text-responder/func.yaml | 13 ---- tools/knative-text-responder/go.mod | 8 --- tools/knative-text-responder/go.sum | 45 ------------- tools/knative-text-responder/handle.go | 59 ----------------- tools/knative-text-responder/handle_test.go | 32 --------- tools/word-length/.funcignore | 5 -- tools/word-length/.gitignore | 5 -- tools/word-length/README.md | 23 ------- tools/word-length/func.yaml | 13 ---- tools/word-length/go.mod | 8 --- tools/word-length/go.sum | 36 ---------- tools/word-length/handle.go | 73 --------------------- tools/word-length/handle_test.go | 32 --------- 17 files changed, 387 deletions(-) delete mode 100644 tools/knative-text-responder/.funcignore delete mode 100644 tools/knative-text-responder/.gitignore delete mode 100644 tools/knative-text-responder/README.md delete mode 100644 tools/knative-text-responder/func.yaml delete mode 100644 tools/knative-text-responder/go.mod delete mode 100644 tools/knative-text-responder/go.sum delete mode 100644 tools/knative-text-responder/handle.go delete mode 100644 tools/knative-text-responder/handle_test.go delete mode 100644 tools/word-length/.funcignore delete mode 100644 tools/word-length/.gitignore delete mode 100644 tools/word-length/README.md delete mode 100644 tools/word-length/func.yaml delete mode 100644 tools/word-length/go.mod delete mode 100644 tools/word-length/go.sum delete mode 100644 tools/word-length/handle.go delete mode 100644 tools/word-length/handle_test.go diff --git a/hack/install.sh b/hack/install.sh index 4e05173..81df3bc 100755 --- a/hack/install.sh +++ b/hack/install.sh @@ -25,8 +25,6 @@ fi (cd tools/resource-cost-calculator && func deploy) (cd tools/average-resource-consumption && func deploy) -(cd tools/knative-text-responder && func deploy) -(cd tools/word-length && func deploy) (cd core/request-proxy && ko apply -f ./config) kubectl apply -f ./core/chat-app/config diff --git a/tools/knative-text-responder/.funcignore b/tools/knative-text-responder/.funcignore deleted file mode 100644 index e8e281c..0000000 --- a/tools/knative-text-responder/.funcignore +++ /dev/null @@ -1,5 +0,0 @@ - -# Use the .funcignore file to exclude files which should not be -# tracked in the image build. To instruct the system not to track -# files in the image build, add the regex pattern or file information -# to this file. diff --git a/tools/knative-text-responder/.gitignore b/tools/knative-text-responder/.gitignore deleted file mode 100644 index 965f0d4..0000000 --- a/tools/knative-text-responder/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ - -# Functions use the .func directory for local runtime data which should -# generally not be tracked in source control. To instruct the system to track -# .func in source control, comment the following line (prefix it with '# '). -/.func diff --git a/tools/knative-text-responder/README.md b/tools/knative-text-responder/README.md deleted file mode 100644 index e329a0d..0000000 --- a/tools/knative-text-responder/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Go Cloud Events Function - -Welcome to your new Go Function! The boilerplate function code can be found in [`handle.go`](handle.go). This Function is meant to respond exclusively to [Cloud Events](https://cloudevents.io/), but you can remove the check for this in the function and it will respond just fine to plain vanilla incoming HTTP requests. - -## Development - -Develop new features by adding a test to [`handle_test.go`](handle_test.go) for each feature, and confirm it works with `go test`. - -Update the running analog of the function using the `func` CLI or client library, and it can be invoked using a manually-created CloudEvent: - -```console -curl -v -X POST -d '{"message": "hello"}' \ - -H'Content-type: application/json' \ - -H'Ce-id: 1' \ - -H'Ce-source: cloud-event-example' \ - -H'Ce-subject: Echo content' \ - -H'Ce-type: MyEvent' \ - -H'Ce-specversion: 1.0' \ - http://localhost:8080/ -``` - -For more, see [the complete documentation]('https://github.com/knative/func/tree/main/docs') - diff --git a/tools/knative-text-responder/func.yaml b/tools/knative-text-responder/func.yaml deleted file mode 100644 index 02469ad..0000000 --- a/tools/knative-text-responder/func.yaml +++ /dev/null @@ -1,13 +0,0 @@ -specVersion: 0.36.0 -name: knative-text-responder -runtime: go -registry: quay.io/cali0707 -image: quay.io/cali0707/knative-text-responder:latest -namespace: default -created: 2024-04-09T10:41:14.850534546-04:00 -invoke: cloudevent -build: - builder: pack -deploy: - namespace: default - image: quay.io/cali0707/knative-text-responder@sha256:fe896781652714e2bf9425b3c4868565866f4f378a26b8f5d8785a045606864b diff --git a/tools/knative-text-responder/go.mod b/tools/knative-text-responder/go.mod deleted file mode 100644 index 9fe4407..0000000 --- a/tools/knative-text-responder/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module function - -go 1.14 - -require ( - github.com/cloudevents/sdk-go/v2 v2.5.0 - github.com/google/uuid v1.6.0 -) diff --git a/tools/knative-text-responder/go.sum b/tools/knative-text-responder/go.sum deleted file mode 100644 index 269511e..0000000 --- a/tools/knative-text-responder/go.sum +++ /dev/null @@ -1,45 +0,0 @@ -github.com/cloudevents/sdk-go/v2 v2.5.0 h1:Ts6aLHbBUJfcNcZ4ouAfJ4+Np7SE1Yf2w4ADKRCd7Fo= -github.com/cloudevents/sdk-go/v2 v2.5.0/go.mod h1:nlXhgFkf0uTopxmRXalyMwS2LG70cRGPrxzmjJgSG0U= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -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/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tools/knative-text-responder/handle.go b/tools/knative-text-responder/handle.go deleted file mode 100644 index 951a2cb..0000000 --- a/tools/knative-text-responder/handle.go +++ /dev/null @@ -1,59 +0,0 @@ -package function - -import ( - "context" - "fmt" - - "github.com/cloudevents/sdk-go/v2/event" - "github.com/google/uuid" -) - -type KnativeRequest struct { - query string `json:"query"` -} - -// Handle an event. -func Handle(ctx context.Context, e event.Event) (*event.Event, error) { - fmt.Println("Received event") - fmt.Println(e) // echo to local output - - req := &KnativeRequest{} - - err := e.DataAs(req) - if err != nil { - fmt.Printf("encountered an error parsing the data: %s\n", err.Error()) - return nil, err - } - fmt.Printf("successfully parsed request: %+v\n", req) - - res := event.New() - res.SetType("knative.dev.info.response") - res.SetSource("/knative-test-responder") - res.SetExtension("responseid", e.ID()) - res.SetID(uuid.NewString()) - err = res.SetData(event.TextPlain, "Knative is a platform-agnostic solution for running serverless deployments. It is made up of 4 key components: Serving, Eventing, Functions, and Client") - if err != nil { - fmt.Printf("encountered an error setting the data: %s\n", err.Error()) - return nil, err - } - - return &res, nil // echo to caller -} - -/* -Other supported function signatures: - - Handle() - Handle() error - Handle(context.Context) - Handle(context.Context) error - Handle(event.Event) - Handle(event.Event) error - Handle(context.Context, event.Event) - Handle(context.Context, event.Event) error - Handle(event.Event) *event.Event - Handle(event.Event) (*event.Event, error) - Handle(context.Context, event.Event) *event.Event - Handle(context.Context, event.Event) (*event.Event, error) - -*/ diff --git a/tools/knative-text-responder/handle_test.go b/tools/knative-text-responder/handle_test.go deleted file mode 100644 index 88d066f..0000000 --- a/tools/knative-text-responder/handle_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package function - -import ( - "context" - "testing" - - "github.com/cloudevents/sdk-go/v2/event" -) - -// TestHandle ensures that Handle accepts a valid CloudEvent without error. -func TestHandle(t *testing.T) { - // Assemble - e := event.New() - e.SetID("id") - e.SetType("type") - e.SetSource("source") - e.SetData("text/plain", "data") - - // Act - echo, err := Handle(context.Background(), e) - if err != nil { - t.Fatal(err) - } - - // Assert - if echo == nil { - t.Errorf("received nil event") // fail on nil - } - if string(echo.Data()) != "data" { - t.Errorf("the received event expected data to be 'data', got '%s'", echo.Data()) - } -} diff --git a/tools/word-length/.funcignore b/tools/word-length/.funcignore deleted file mode 100644 index e8e281c..0000000 --- a/tools/word-length/.funcignore +++ /dev/null @@ -1,5 +0,0 @@ - -# Use the .funcignore file to exclude files which should not be -# tracked in the image build. To instruct the system not to track -# files in the image build, add the regex pattern or file information -# to this file. diff --git a/tools/word-length/.gitignore b/tools/word-length/.gitignore deleted file mode 100644 index 965f0d4..0000000 --- a/tools/word-length/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ - -# Functions use the .func directory for local runtime data which should -# generally not be tracked in source control. To instruct the system to track -# .func in source control, comment the following line (prefix it with '# '). -/.func diff --git a/tools/word-length/README.md b/tools/word-length/README.md deleted file mode 100644 index e329a0d..0000000 --- a/tools/word-length/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Go Cloud Events Function - -Welcome to your new Go Function! The boilerplate function code can be found in [`handle.go`](handle.go). This Function is meant to respond exclusively to [Cloud Events](https://cloudevents.io/), but you can remove the check for this in the function and it will respond just fine to plain vanilla incoming HTTP requests. - -## Development - -Develop new features by adding a test to [`handle_test.go`](handle_test.go) for each feature, and confirm it works with `go test`. - -Update the running analog of the function using the `func` CLI or client library, and it can be invoked using a manually-created CloudEvent: - -```console -curl -v -X POST -d '{"message": "hello"}' \ - -H'Content-type: application/json' \ - -H'Ce-id: 1' \ - -H'Ce-source: cloud-event-example' \ - -H'Ce-subject: Echo content' \ - -H'Ce-type: MyEvent' \ - -H'Ce-specversion: 1.0' \ - http://localhost:8080/ -``` - -For more, see [the complete documentation]('https://github.com/knative/func/tree/main/docs') - diff --git a/tools/word-length/func.yaml b/tools/word-length/func.yaml deleted file mode 100644 index 967b171..0000000 --- a/tools/word-length/func.yaml +++ /dev/null @@ -1,13 +0,0 @@ -specVersion: 0.36.0 -name: word-length -runtime: go -registry: quay.io/cali0707/word-length -image: quay.io/cali0707/word-length/word-length:latest -namespace: default -created: 2024-04-10T13:58:47.000036865-04:00 -invoke: cloudevent -build: - builder: pack -deploy: - namespace: default - image: quay.io/cali0707/word-length/word-length@sha256:9e025b884c38eba90ab468f6aa59eebc26da737de0bc743db3b4e8d4d68d85af diff --git a/tools/word-length/go.mod b/tools/word-length/go.mod deleted file mode 100644 index 9fe4407..0000000 --- a/tools/word-length/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module function - -go 1.14 - -require ( - github.com/cloudevents/sdk-go/v2 v2.5.0 - github.com/google/uuid v1.6.0 -) diff --git a/tools/word-length/go.sum b/tools/word-length/go.sum deleted file mode 100644 index 97c5845..0000000 --- a/tools/word-length/go.sum +++ /dev/null @@ -1,36 +0,0 @@ -github.com/cloudevents/sdk-go/v2 v2.5.0 h1:Ts6aLHbBUJfcNcZ4ouAfJ4+Np7SE1Yf2w4ADKRCd7Fo= -github.com/cloudevents/sdk-go/v2 v2.5.0/go.mod h1:nlXhgFkf0uTopxmRXalyMwS2LG70cRGPrxzmjJgSG0U= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/tools/word-length/handle.go b/tools/word-length/handle.go deleted file mode 100644 index 18042e3..0000000 --- a/tools/word-length/handle.go +++ /dev/null @@ -1,73 +0,0 @@ -package function - -import ( - "context" - "fmt" - - "github.com/cloudevents/sdk-go/v2/event" - "github.com/google/uuid" -) - -type WordLengthRequest struct { - Words []string `json:"words"` -} - -// Handle an event. -func Handle(ctx context.Context, e event.Event) (*event.Event, error) { - /* - * YOUR CODE HERE - * - * Try running `go test`. Add more test as you code in `handle_test.go`. - */ - - fmt.Println("Received event") - fmt.Println(e) // echo to local output - - req := &WordLengthRequest{} - resp := event.New() - resp.SetID(uuid.NewString()) - resp.SetSource("/word-length") - resp.SetExtension("responseid", e.ID()) - - err := e.DataAs(req) - if err != nil { - fmt.Printf("failed to decode data: %s", err.Error()) - resp.SetType("word.length.error.response") - resp.SetData(event.TextPlain, fmt.Sprintf("Unable to decode the request received: %s", err.Error())) - return &resp, err - } - lengths := make(map[string]int) - - for _, w := range req.Words { - lengths[w] = len(w) - } - - resp.SetType("word.length.result.response") - err = resp.SetData(event.TextJSON, lengths) - if err != nil { - fmt.Printf("failed to encode result: %s", err.Error()) - resp.SetType("word.length.error.response") - resp.SetData(event.TextPlain, fmt.Sprintf("Unable to process the request: %s", err.Error())) - return &resp, err - } - - return &resp, nil // echo to caller -} - -/* -Other supported function signatures: - - Handle() - Handle() error - Handle(context.Context) - Handle(context.Context) error - Handle(event.Event) - Handle(event.Event) error - Handle(context.Context, event.Event) - Handle(context.Context, event.Event) error - Handle(event.Event) *event.Event - Handle(event.Event) (*event.Event, error) - Handle(context.Context, event.Event) *event.Event - Handle(context.Context, event.Event) (*event.Event, error) - -*/ diff --git a/tools/word-length/handle_test.go b/tools/word-length/handle_test.go deleted file mode 100644 index 88d066f..0000000 --- a/tools/word-length/handle_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package function - -import ( - "context" - "testing" - - "github.com/cloudevents/sdk-go/v2/event" -) - -// TestHandle ensures that Handle accepts a valid CloudEvent without error. -func TestHandle(t *testing.T) { - // Assemble - e := event.New() - e.SetID("id") - e.SetType("type") - e.SetSource("source") - e.SetData("text/plain", "data") - - // Act - echo, err := Handle(context.Background(), e) - if err != nil { - t.Fatal(err) - } - - // Assert - if echo == nil { - t.Errorf("received nil event") // fail on nil - } - if string(echo.Data()) != "data" { - t.Errorf("the received event expected data to be 'data', got '%s'", echo.Data()) - } -}