From 1e228ed338de91293529da4237059fd61b097998 Mon Sep 17 00:00:00 2001 From: ange Date: Sat, 28 Sep 2024 16:16:52 +0000 Subject: [PATCH] go backend (#1) Reviewed-on: https://git.gmoker.com/yw5n/yw5ncom/pulls/1 --- .gitignore | 27 +++++++++++++++++++++++++++ Dockerfile | 14 ++++++++++---- compose.yaml | 2 +- html/about.html | 8 ++++---- html/index.html | 12 ++++++------ html/resume.html | 8 ++++---- manifests/common/app.yaml | 2 +- nginx.conf | 14 -------------- src/main.go | 33 +++++++++++++++++++++++++++++++++ src/vars/vars.go | 19 +++++++++++++++++++ 10 files changed, 105 insertions(+), 34 deletions(-) create mode 100644 .gitignore delete mode 100644 nginx.conf create mode 100644 src/main.go create mode 100644 src/vars/vars.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d19c362 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Created by https://www.toptal.com/developers/gitignore/api/go +# Edit at https://www.toptal.com/developers/gitignore?templates=go + +### 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 + +# End of https://www.toptal.com/developers/gitignore/api/go diff --git a/Dockerfile b/Dockerfile index ff17805..975cfad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,10 @@ -FROM docker.io/nginx:latest -COPY nginx.conf /etc/nginx/conf.d/default.conf -COPY html/ /usr/share/nginx/html/ -COPY static/ /usr/share/nginx/static/ +FROM docker.io/golang:1.23 as build +COPY src/ . +RUN printf 'module yw5n\ngo 1.23' > go.mod && CGO_ENABLED=0 go build -o /app + +FROM scratch +COPY --from=build /app /app +COPY static/ /static/ +COPY html/ /html/ +EXPOSE 3000 +CMD ["/app"] diff --git a/compose.yaml b/compose.yaml index 64d7e3b..89ab5a7 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,4 +3,4 @@ services: app: build: . ports: - - "8000:80" + - "3000:3000" diff --git a/html/about.html b/html/about.html index 78a3433..9ff6258 100644 --- a/html/about.html +++ b/html/about.html @@ -9,14 +9,14 @@
diff --git a/html/index.html b/html/index.html index 86eb692..c0b9e9c 100644 --- a/html/index.html +++ b/html/index.html @@ -9,16 +9,16 @@
@@ -36,11 +36,11 @@
- + - +
Matrix (Element)@ange:gmoker.com
Matrix (Element)@ange:gmoker.com
Discord@elrilio
Phone (France)+33 5 82 95 16 23
Emailange@yw5n.com
WhatsApp+62 853-3355-9453
WhatsApp+62 853-3355-9453
diff --git a/html/resume.html b/html/resume.html index 99ab106..e42e9c1 100644 --- a/html/resume.html +++ b/html/resume.html @@ -9,16 +9,16 @@ diff --git a/manifests/common/app.yaml b/manifests/common/app.yaml index 3981559..190b834 100644 --- a/manifests/common/app.yaml +++ b/manifests/common/app.yaml @@ -61,4 +61,4 @@ spec: imagePullPolicy: Always ports: - name: http - containerPort: 80 + containerPort: 3000 diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index dccd762..0000000 --- a/nginx.conf +++ /dev/null @@ -1,14 +0,0 @@ -server { - listen 80; - listen [::]:80; - server_name localhost; - - location / { - root /usr/share/nginx/html; - index index.html; - } - - location /static/ { - root /usr/share/nginx/; - } -} diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..e5309d1 --- /dev/null +++ b/src/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "log" + "net/http" + "path/filepath" + "strings" +) + +func html(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/style.css" { + http.ServeFile(w, r, "/html/style.css") + return + } + if strings.HasPrefix(r.URL.Path, "/static/") { + http.ServeFile(w, r, r.URL.Path) + return + } + if r.URL.Path == "/" { + http.ServeFile(w, r, "/html/index.html") + return + } + http.ServeFile(w, r, filepath.Join("/html", r.URL.Path + ".html")) +} + +func main() { + http.HandleFunc("/", html) + + err := http.ListenAndServe(":3000", nil) + if err != nil { + log.Fatal(err) + } +} diff --git a/src/vars/vars.go b/src/vars/vars.go new file mode 100644 index 0000000..5108d04 --- /dev/null +++ b/src/vars/vars.go @@ -0,0 +1,19 @@ +package vars + +import ( + "path/filepath" +) + +var ( + templates string + static string + html string + css string +) + +func init() { + templates = "templates" + static = "static" + html = filepath.Join(static, "html") + css = filepath.Join(static, "css") +}