From 18be049f05125c4dd111e0afdc019877c0d0d9b4 Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Thu, 14 Sep 2023 20:35:35 +0200 Subject: [PATCH] initial commit --- Dockerfile | 11 +++++++++++ compose.yml | 9 +++++++++ go.mod | 3 +++ main.go | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 Dockerfile create mode 100644 compose.yml create mode 100644 go.mod create mode 100644 main.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ebf77d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:latest + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . +RUN go build -v -o ./bin/server . + +CMD ["./bin/server"] \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..2436ffa --- /dev/null +++ b/compose.yml @@ -0,0 +1,9 @@ +version: '3' +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "127.14.115.95:1091:4000" + restart: unless-stopped diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..997c8f4 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.phc.dm.unipi.it/phc/portainer-example + +go 1.21.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..c1554ff --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "encoding/json" + "log" + "mime" + "net/http" +) + +func main() { + r := http.NewServeMux() + r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + return + } + + w.Header().Set("Content-Type", mime.TypeByExtension(".json")) + if err := json.NewEncoder(w).Encode("ok"); err != nil { + log.Fatal(err) + return + } + }) + + log.Fatal(http.ListenAndServe(":4000", r)) +}