Migrer string html vers package embed #3
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 ./
|
||||
|
||||
ADD embed/ embed/
|
||||
|
||||
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o app .
|
||||
|
||||
# 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 (
|
||||
"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"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue