Migrer string html vers package embed #3

Merged
vlbeaudoin merged 1 commit from feature/embed into main 2023-02-23 04:28:39 -05:00
5 changed files with 37 additions and 13 deletions

View file

@ -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

12
embed/embed.go Normal file
View file

@ -0,0 +1,12 @@
package embed
import (
_ "embed"
)
//go:embed html/index.html
var html_index string
func ReadHtml() string {
return html_index
}

13
embed/html/index.html Normal file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>AGECEM</title>
<style>
body {text-align: center;}
</style>
</head>
<body>
<h1>Association Générale Étudiante du Cégep Édouard-Montpetit</h1>
</body>
</html>

View file

@ -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, `<!DOCTYPE html>
<html>
<head>
<title>AGECEM</title>
<style>
body {text-align: center;}
</style>
</head>
<body>
<h1># agecem.org</h1>
</body>
</html>`)
return c.HTML(http.StatusOK, html)
})
e.Logger.Fatal(e.Start(":8080"))
}