From fcab53ba2e87776c469defdbe9100b690df411f2 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Thu, 23 Feb 2023 04:24:04 -0500 Subject: [PATCH] Migrer string html vers package embed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Permet d'intégrer des fichiers texte dans le fichier exécutable. Copier répertoire embed/ ainsi que son contenu dans le container. Ajouter embed.ReadHtml() qui retourne le contenu de embed/html/index.html Exécuter go fmt --- Dockerfile | 2 ++ embed/embed.go | 12 ++++++++++++ embed/html/index.html | 13 +++++++++++++ main.go | 2 +- server.go | 21 +++++++++------------ 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 embed/embed.go create mode 100644 embed/html/index.html diff --git a/Dockerfile b/Dockerfile index b4f5d42..93e299e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,8 @@ WORKDIR /go/src/app COPY go.mod go.sum main.go server.go ./ +ADD embed/ embed/ + RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o app . # Alpine diff --git a/embed/embed.go b/embed/embed.go new file mode 100644 index 0000000..02eed70 --- /dev/null +++ b/embed/embed.go @@ -0,0 +1,12 @@ +package embed + +import ( + _ "embed" +) + +//go:embed html/index.html +var html_index string + +func ReadHtml() string { + return html_index +} diff --git a/embed/html/index.html b/embed/html/index.html new file mode 100644 index 0000000..49fa95f --- /dev/null +++ b/embed/html/index.html @@ -0,0 +1,13 @@ + + + + + AGECEM + + + +

Association Générale Étudiante du Cégep Édouard-Montpetit

+ + diff --git a/main.go b/main.go index 5c8ff3a..736ef31 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ package main func main() { - Execute() + Execute() } diff --git a/server.go b/server.go index 0a7180d..7c52fee 100644 --- a/server.go +++ b/server.go @@ -3,24 +3,21 @@ package main import ( "net/http" + "git.agecem.com/agecem/agecem-org/embed" "github.com/labstack/echo/v4" ) +var html string + +func init() { + html = embed.ReadHtml() +} + func Execute() { e := echo.New() + e.GET("/", func(c echo.Context) error { - return c.HTML(http.StatusOK, ` - - - AGECEM - - - -

# agecem.org

- - `) + return c.HTML(http.StatusOK, html) }) e.Logger.Fatal(e.Start(":8080")) } -- 2.45.2