Migrer string html vers package embed
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
This commit is contained in:
parent
bef140dd5d
commit
fcab53ba2e
5 changed files with 37 additions and 13 deletions
|
@ -6,6 +6,8 @@ WORKDIR /go/src/app
|
||||||
|
|
||||||
COPY go.mod go.sum main.go server.go ./
|
COPY go.mod go.sum main.go server.go ./
|
||||||
|
|
||||||
|
ADD embed/ embed/
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o app .
|
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o app .
|
||||||
|
|
||||||
# Alpine
|
# Alpine
|
||||||
|
|
12
embed/embed.go
Normal file
12
embed/embed.go
Normal 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
13
embed/html/index.html
Normal 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>
|
21
server.go
21
server.go
|
@ -3,24 +3,21 @@ package main
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.agecem.com/agecem/agecem-org/embed"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var html string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
html = embed.ReadHtml()
|
||||||
|
}
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
e.GET("/", func(c echo.Context) error {
|
e.GET("/", func(c echo.Context) error {
|
||||||
return c.HTML(http.StatusOK, `<!DOCTYPE html>
|
return c.HTML(http.StatusOK, html)
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>AGECEM</title>
|
|
||||||
<style>
|
|
||||||
body {text-align: center;}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1># agecem.org</h1>
|
|
||||||
</body>
|
|
||||||
</html>`)
|
|
||||||
})
|
})
|
||||||
e.Logger.Fatal(e.Start(":8080"))
|
e.Logger.Fatal(e.Start(":8080"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue