File tree Expand file tree Collapse file tree 4 files changed +66
-42
lines changed Expand file tree Collapse file tree 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
22
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
38
49EXPOSE 8000
510
611# Create app directory
712WORKDIR /usr/src/app
813
14+ COPY --from=builder /usr/src/build/handler.bin .
15+
916COPY . .
17+ RUN rm functionhandler.go
1018RUN mv fn/* .
1119RUN chmod +x fn.sh
1220
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)
55
66# echo the variable to stdout
77echo -n " $INPUT "
8-
You can’t perform that action at this time.
0 commit comments