File tree 4 files changed +66
-42
lines changed
4 files changed +66
-42
lines changed Original file line number Diff line number Diff line change 1
- FROM python:3.11 -alpine
1
+ FROM golang:1.20 -alpine AS builder
2
2
3
+ WORKDIR /usr/src/build
4
+ COPY functionhandler.go .
5
+ RUN GO111MODULE=off CGO_ENABLED=0 go build -o handler.bin .
6
+
7
+ FROM alpine
3
8
4
9
EXPOSE 8000
5
10
6
11
# Create app directory
7
12
WORKDIR /usr/src/app
8
13
14
+ COPY --from=builder /usr/src/build/handler.bin .
15
+
9
16
COPY . .
17
+ RUN rm functionhandler.go
10
18
RUN mv fn/* .
11
19
RUN chmod +x fn.sh
12
20
13
- CMD [ "python3" , "functionhandler.py " ]
21
+ CMD [ "./handler.bin " ]
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "bytes"
5
+ "fmt"
6
+ "io"
7
+ "log"
8
+ "net/http"
9
+ "os/exec"
10
+ )
11
+
12
+ func main () {
13
+ port := ":8000"
14
+
15
+ http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
16
+ switch r .Method {
17
+ case http .MethodGet :
18
+ if r .URL .Path == "/health" {
19
+ w .WriteHeader (http .StatusOK )
20
+ fmt .Fprint (w , "OK" )
21
+ log .Println ("reporting health: OK" )
22
+ return
23
+ }
24
+ w .WriteHeader (http .StatusNotFound )
25
+ return
26
+
27
+ case http .MethodPost :
28
+ data , err := io .ReadAll (r .Body )
29
+ if err != nil {
30
+ w .WriteHeader (http .StatusInternalServerError )
31
+ fmt .Fprint (w , err )
32
+ return
33
+ }
34
+ cmd := exec .Command ("./fn.sh" )
35
+ cmd .Stdin = bytes .NewReader (data )
36
+ output , err := cmd .CombinedOutput ()
37
+ if err != nil {
38
+ w .WriteHeader (http .StatusInternalServerError )
39
+ fmt .Fprint (w , err )
40
+ return
41
+ }
42
+ w .WriteHeader (http .StatusOK )
43
+ w .Write (output )
44
+ return
45
+ default :
46
+ w .WriteHeader (http .StatusMethodNotAllowed )
47
+ return
48
+ }
49
+ })
50
+
51
+ log .Printf ("Server listening on port %s\n " , port )
52
+ err := http .ListenAndServe (port , nil )
53
+ if err != nil {
54
+ log .Fatal (err )
55
+ }
56
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -5,4 +5,3 @@ INPUT=$(cat)
5
5
6
6
# echo the variable to stdout
7
7
echo -n " $INPUT "
8
-
You can’t perform that action at this time.
0 commit comments