From 5d632da7719d8dfe0e194ce89710ea8bc3b40f4b Mon Sep 17 00:00:00 2001 From: nxshock Date: Fri, 24 Sep 2021 23:35:55 +0500 Subject: [PATCH] Move site files to separate embed.FS --- handlers.go | 2 +- index.htm | 200 ----------------------------------------------- site.go | 15 ++++ site/favicon.svg | 1 + site/index.htm | 71 +++++++++++++++++ site/style.css | 128 ++++++++++++++++++++++++++++++ templates.go | 7 +- 7 files changed, 217 insertions(+), 207 deletions(-) delete mode 100644 index.htm create mode 100644 site.go create mode 100644 site/favicon.svg create mode 100644 site/index.htm create mode 100644 site/style.css diff --git a/handlers.go b/handlers.go index 23a0916..5e3f47f 100644 --- a/handlers.go +++ b/handlers.go @@ -13,7 +13,7 @@ import ( func HandleRoot(w http.ResponseWriter, r *http.Request) { if r.RequestURI != "/" { - http.Error(w, "", http.StatusNotFound) + http.FileServer(http.FS(stripSiteFS)).ServeHTTP(w, r) return } diff --git a/index.htm b/index.htm deleted file mode 100644 index cd37832..0000000 --- a/index.htm +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - - File Storage - - - - - -
- - - File Storage - - -
-
- - - - - - - - - -{{range .Files}} - - - - -{{end}}
Имя файлаРазмерДата
{{.Name}}
{{.Size}}
{{.Date}}
-
- - - - - diff --git a/site.go b/site.go new file mode 100644 index 0000000..c4c8140 --- /dev/null +++ b/site.go @@ -0,0 +1,15 @@ +package main + +import ( + "embed" + "io/fs" +) + +//go:embed site/* +var siteFS embed.FS + +var stripSiteFS fs.FS + +func init() { + stripSiteFS, _ = fs.Sub(siteFS, "site") +} diff --git a/site/favicon.svg b/site/favicon.svg new file mode 100644 index 0000000..6291be8 --- /dev/null +++ b/site/favicon.svg @@ -0,0 +1 @@ + diff --git a/site/index.htm b/site/index.htm new file mode 100644 index 0000000..0717478 --- /dev/null +++ b/site/index.htm @@ -0,0 +1,71 @@ + + + + + + + File Storage + + + + + +
+ + + File Storage + + +
+
+ + + + + + + + + +{{range .Files}} + + + + +{{end}}
Имя файлаРазмерДата
{{.Name}}
{{.Size}}
{{.Date}}
+
+ + + + + diff --git a/site/style.css b/site/style.css new file mode 100644 index 0000000..3518f39 --- /dev/null +++ b/site/style.css @@ -0,0 +1,128 @@ +* { + font-family: Verdana; + font-size: 16px; + color: #abb2bf; + margin: .5em; + padding: 0; +} + +html { + margin: 0; + padding: 0; + height: 100% +} + +body { + background-color: #282c34; + display: flex; + justify-content: space-between; + flex-wrap: nowrap; + flex-direction: column; + height: 100%; + margin: 0; + padding: 0; +} + +a { + text-decoration: none; + color: #61afef; + margin: 0; +} + +svg, img { + vertical-align: middle; + width: 1em; + height: 1em; + margin: 0; + padding: 0; +} + +header, footer { + flex-grow: 0; + background-color: #353b45; + padding: .5em; + margin: 0; + display: flex; + justify-content: space-between; + align-items: center; +} + +main { + flex-grow: 1; +} + +header { + border-bottom: 1px solid #3e4451; +} + +footer { + border-top: 1px solid #3e4451; + font-size: 75%; +} + +h1 { + margin-top: 1em; + font-size: 150%; +} + +table { + border-collapse: collapse; + width: 100%; + margin: 0; +} + +tr:hover { + background-color: #353b45; +} + +th, td { + border: 1px solid #3e4451; + padding: 0.5em; +} + +td:nth-child(2) { + width: 5em; + text-align: right; +} + +td:nth-child(3) { + width: 6em; + text-align: right; +} + +th { + background-color: #353b45; +} + +form { + width: calc(100% - 1em); +} + +form > input { + width: calc(100% - 2em); + padding: .5em; +} + +button { + padding: .5em; + margin: 0; +} + +pre { + margin: 0; + font-family: monospace; +} + +input[type="file"] { + display: none; +} + +label { + border-radius: 0.25em; + background-color: #61afef; + margin: 0; + padding: .5em; + cursor: pointer; + color: #fff; + text-shadow: 1px 1px 1px #000; +} diff --git a/templates.go b/templates.go index 43da7a2..8a1a8b3 100644 --- a/templates.go +++ b/templates.go @@ -1,15 +1,11 @@ package main import ( - "embed" "html/template" log "github.com/sirupsen/logrus" ) -//go:embed index.htm -var templatesFS embed.FS - var templates *template.Template func initTemplates() error { @@ -17,11 +13,10 @@ func initTemplates() error { defer log.Debugln("Templates initialization finished.") var err error - templates, err = template.ParseFS(templatesFS, "*.htm") + templates, err = template.ParseFS(siteFS, "site/index.htm") if err != nil { return err } - templatesFS = embed.FS{} // free memory return nil }