From bde60f016d4cd0161562d7c84bf7b1068293dc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Kubri=C4=8Dan?= Date: Fri, 6 Sep 2024 21:49:04 +0200 Subject: [PATCH] dockerized --- .air.toml | 44 ++++++++++++++++++++++++++++++++++++++++++++ about.html | 6 ------ blog.html | 11 ----------- dockerfile | 24 ++++++++++++++++++++++++ go.mod | 19 +++++++++++++++++++ go.sum | 35 +++++++++++++++++++++++++++++++++++ index.html | 31 ------------------------------- src/main.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ views/index.html | 25 +++++++++++++++++++++++++ 9 files changed, 194 insertions(+), 48 deletions(-) create mode 100644 .air.toml delete mode 100644 about.html delete mode 100644 blog.html create mode 100644 dockerfile create mode 100644 go.mod create mode 100644 go.sum delete mode 100644 index.html create mode 100644 src/main.go create mode 100644 views/index.html diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..af9137e --- /dev/null +++ b/.air.toml @@ -0,0 +1,44 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "./tmp/main" + cmd = "go build -o ./tmp/main src/main.go" + delay = 0 + exclude_dir = ["node_modules", "assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = ["cmd", "views", "pkg"] + include_ext = ["go", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/about.html b/about.html deleted file mode 100644 index 6f05b25..0000000 --- a/about.html +++ /dev/null @@ -1,6 +0,0 @@ -
-

- Zbytočnosť pokusov o charaketizovania osoby v jednom krátkom odstavci je - jeden z dóvodov prečo exituje táto stránka -

-
diff --git a/blog.html b/blog.html deleted file mode 100644 index 0fc7b13..0000000 --- a/blog.html +++ /dev/null @@ -1,11 +0,0 @@ -
-

Blog

-
-

Post 1

-

This is the content of the first blog post. It's an introduction to some of the exciting projects I've been working on recently.

-
-
-

Post 2

-

This is the content of the second blog post. Here I share some tips and tricks on improving your web development workflow.

-
-
diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..c8213ec --- /dev/null +++ b/dockerfile @@ -0,0 +1,24 @@ +# Step 1: Build the Go binary +FROM golang:bookworm AS build + +# Set the current working directory inside the container +WORKDIR /app + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download all Go dependencies +RUN go mod download + +# Copy the rest of the application code +COPY . . + +# Build the Go application +RUN go build -o main src/main.go + +# Command to run the executable +RUN chmod a+x main +CMD ["./main"] + +# Expose the port on which the Go server will run +EXPOSE 80 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d25a5ef --- /dev/null +++ b/go.mod @@ -0,0 +1,19 @@ +module knet.sk + +go 1.22.6 + +require github.com/labstack/echo/v4 v4.12.0 + +require ( + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/labstack/gommon v0.4.2 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/time v0.5.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cadc1f3 --- /dev/null +++ b/go.sum @@ -0,0 +1,35 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= +github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= +github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= +github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/index.html b/index.html deleted file mode 100644 index ac05d53..0000000 --- a/index.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - Home - - - - -
-

John Doe - Developer

-
- - - -
-
-

Welcome

-

Welcome to my personal website. I'm a developer specializing in web technologies. Check out my blog for the latest updates.

-
-
- - - - \ No newline at end of file diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..8d21876 --- /dev/null +++ b/src/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "html/template" + "io" + + "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" +) + +type Templates struct { + templates *template.Template +} + +func (t *Templates) Render(w io.Writer, name string, data interface{}, c echo.Context) error { + return t.templates.ExecuteTemplate(w, name, data) +} + +func NewTemplates() *Templates { + return &Templates{ + templates: template.Must(template.ParseGlob("views/*.html")), + } +} + +type Page struct { +} + +func newPage() Page { + return Page{} +} + +func main() { + e := echo.New() + e.Renderer = NewTemplates() + e.Use(middleware.Logger()) + + page := newPage() + + e.Static("/images", "images") + e.Static("/css", "css") + + e.GET("/", func(c echo.Context) error { + return c.Render(200, "index", page) + }) + + e.Logger.Fatal(e.Start(":5000")) +} diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..29363f5 --- /dev/null +++ b/views/index.html @@ -0,0 +1,25 @@ +{{block "index" .}} + + + + + + Home + + + + + + +
+
+

+ Nothing to see here... +

+
+
+ + + + +{{end}} \ No newline at end of file