From 96b4c8f931223864d032224e1ee0a965a85be65d Mon Sep 17 00:00:00 2001 From: James Newman Date: Wed, 12 Jun 2024 12:44:00 +0100 Subject: [PATCH] init repo --- .gitea/workflows/checks.yaml | 32 ++++++++++++++++++++++++++++++++ .gitignore | 22 ++++++++++++++++++++++ Dockerfile | 11 +++++++++++ README.md | 12 ++++++++++++ go.mod | 3 +++ index.html | 35 +++++++++++++++++++++++++++++++++++ main.go | 30 ++++++++++++++++++++++++++++++ 7 files changed, 145 insertions(+) create mode 100644 .gitea/workflows/checks.yaml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 go.mod create mode 100644 index.html create mode 100644 main.go diff --git a/.gitea/workflows/checks.yaml b/.gitea/workflows/checks.yaml new file mode 100644 index 0000000..d665d0f --- /dev/null +++ b/.gitea/workflows/checks.yaml @@ -0,0 +1,32 @@ +name: Go Checks +run-name: Go Checks +on: [push] + +jobs: + checks: + name: checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + check-latest: true + cache: true + + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@latest + + - name: Go Tidy + run: go mod tidy && git diff --exit-code + - name: Go Mod + run: go mod download + - name: Go Mod Verify + run: go mod verify + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + + - name: Run govulncheck + run: govulncheck -test ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7aecaf --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Editor Files +.idea +.fleet +.vscode + +# 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 + +# Go workspace file +go.work +go.work.sum + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2f4226 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.22 + +WORKDIR /app +COPY main.go ./ + +RUN CGO_ENABLED=0 GOOS=linux go build -o /hello-world + +EXPOSE 8080 + +# Run +CMD ["/hello-world"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..c88b124 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Hello World +## A small project used in our series ("Self-hosting Git with CI/CD, using Gitea, Actions and its Container registry")[https://thehomelabber.com/guides/self-hosted-git-ci-cd] + +To use this, clone the repository locally and change the remote origin to your new repository: +```bash +git clone git@github.com:TheHomelabber/self-hosted-git-hello-world.git -o hello-world +cd hello-world +git remote remove git@github.com:TheHomelabber/self-hosted-git-hello-world.git + +# Change the origin to your repository. +git remote add origin git@git.example.com:Example/self-hosted-git-hello-world.git +``` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..af89063 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module helloworld + +go 1.22 diff --git a/index.html b/index.html new file mode 100644 index 0000000..7d87eeb --- /dev/null +++ b/index.html @@ -0,0 +1,35 @@ + + + + + + + Hello {{.}}! + + + + +

Hello, {{.}}!

+ + diff --git a/main.go b/main.go new file mode 100644 index 0000000..ea5f718 --- /dev/null +++ b/main.go @@ -0,0 +1,30 @@ +package main + +import ( + "html/template" + "log" + "net/http" + "strings" +) + +func main() { + http.HandleFunc("/", handler) + log.Fatal(http.ListenAndServe(":8080", nil)) +} + +func handler(w http.ResponseWriter, r *http.Request) { + name := strings.Replace(r.URL.Path, "/", "", 1) + if name == "" { + name = "World" + } + + t, err := template.ParseFiles("index.html") + if err != nil { + log.Fatal("error parsing template: ", err) + } + + err = t.Execute(w, name) + if err != nil { + log.Fatal("error executing template: ", err) + } +}