commit c6efed07f519b9f8ef32950a612da784c0975c22 Author: Fred Boniface Date: Fri Dec 5 16:30:34 2025 +0000 Initial diff --git a/.gitea/workflows/build-push.yaml b/.gitea/workflows/build-push.yaml new file mode 100644 index 0000000..06056b9 --- /dev/null +++ b/.gitea/workflows/build-push.yaml @@ -0,0 +1,39 @@ +name: Build and Push container image +run-name: ${{ gitea.actor }} is building and pushing + +on: + create: + tags: "*" + +env: + GITEA_DOMAIN: git.fjla.uk + GITEA_REGISTRY_USER: fred.boniface + RESULT_IMAGE_NAME: fred.boniface/echoreq + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + options: --privileged + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.GITEA_DOMAIN }} + username: ${{ env.GITEA_REGISTRY_USER }} + password: ${{ secrets.REGISTRY_TOKEN }} + - name: Build and Push image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: | + ${{ env.GITEA_DOMAIN }}/${{ env.RESULT_IMAGE_NAME }}:${{ gitea.ref_name }} + ${{ env.GITEA_DOMAIN }}/${{ env.RESULT_IMAGE_NAME }}:latest \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b90e79 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# ---> Go +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8d14ab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.24-alpine AS builder +WORKDIR /app +COPY src/main.go . +RUN CGO_ENABLED=0 GOOS=linux go build -o echo-server main.go + +FROM scratch +WORKDIR /app +COPY --from=builder /app/echo-server . +EXPOSE 8080 +ENTRYPOINT [ "/app/echo-server" ] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eb6103a --- /dev/null +++ b/LICENSE @@ -0,0 +1,5 @@ +Copyright (C) 2025 by fred.boniface fjla@fredboniface.co.uk + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8859b13 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# echoreq + +Simple application that echo's the HTTP Request as received by the server. Useful for debugging. \ No newline at end of file diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..93276f2 --- /dev/null +++ b/src/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func echoHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "%s %s\n", r.Method, r.URL.String()) + + fmt.Fprintln(w, "Headers:") + for name, values := range r.Header { + for _, value := range values { + fmt.Fprintf(w, "%s: %s\n", name, value) + } + } + + fmt.Fprintln(w, "\nBody:") + r.Body.Close() +} + +func main() { + http.HandleFunc("/", echoHandler) + port := "8080" + log.Printf("Starting echo server on port %s...\n", port) + log.Fatal(http.ListenAndServe(":"+port, nil)) +}