Browse Source

Статические файлы добавлены в бинарник

master
Krio 4 years ago
parent
commit
fa92edbc70
  1. 9
      main.go
  2. 0
      static/favicon.png
  3. 4
      static/index.html
  4. 0
      static/styles.css

9
main.go

@ -1,18 +1,22 @@
package main package main
import ( import (
"embed"
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
) )
//go:embed static
var staticFiles embed.FS
type Guestbook struct { type Guestbook struct {
Comments []string Comments []string
Count int Count int
} }
func indexHandler(writer http.ResponseWriter, request *http.Request) { func indexHandler(writer http.ResponseWriter, request *http.Request) {
html, err := template.ParseFiles("html/index.html") html, err := template.ParseFS(staticFiles, "static/index.html")
check(err) check(err)
store := TxtStore("comments.txt") store := TxtStore("comments.txt")
@ -37,7 +41,8 @@ func main() {
http.HandleFunc("/", indexHandler) http.HandleFunc("/", indexHandler)
http.HandleFunc("/new", newHandler) http.HandleFunc("/new", newHandler)
http.Handle("/html/", http.StripPrefix("/html/", http.FileServer(http.Dir("html")))) var staticFS = http.FS(staticFiles)
http.Handle("/static/", http.FileServer(staticFS))
err := http.ListenAndServe("0.0.0.0:80", nil) err := http.ListenAndServe("0.0.0.0:80", nil)
log.Fatal(err) log.Fatal(err)

0
html/favicon.png → static/favicon.png

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

4
html/index.html → static/index.html

@ -4,8 +4,8 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Книга отзывов</title> <title>Книга отзывов</title>
<link rel="icon" type="image/png" sizes="256x256" href="/html/favicon.png"> <link rel="icon" type="image/png" sizes="256x256" href="static/favicon.png">
<link rel="stylesheet" type="text/css" href="html/styles.css"> <link rel="stylesheet" type="text/css" href="static/styles.css">
</head> </head>
<body> <body>

0
html/styles.css → static/styles.css

Loading…
Cancel
Save