diff --git a/web/embed/embed.go b/web/embed/embed.go new file mode 100644 index 0000000..b12cf12 --- /dev/null +++ b/web/embed/embed.go @@ -0,0 +1,9 @@ +package embed + +import "embed" + +//go:embed templates +var TemplatesFS embed.FS + +//go:embed static +var StaticFS embed.FS diff --git a/web/static/css/font-awesome.6.4.0.min.css b/web/embed/static/css/font-awesome.6.4.0.min.css similarity index 100% rename from web/static/css/font-awesome.6.4.0.min.css rename to web/embed/static/css/font-awesome.6.4.0.min.css diff --git a/web/static/css/skazanull.css b/web/embed/static/css/skazanull.css similarity index 100% rename from web/static/css/skazanull.css rename to web/embed/static/css/skazanull.css diff --git a/web/static/css/tailwind-custom.css b/web/embed/static/css/tailwind-custom.css similarity index 100% rename from web/static/css/tailwind-custom.css rename to web/embed/static/css/tailwind-custom.css diff --git a/web/static/images/android-icon-144x144.png b/web/embed/static/images/android-icon-144x144.png similarity index 100% rename from web/static/images/android-icon-144x144.png rename to web/embed/static/images/android-icon-144x144.png diff --git a/web/static/images/android-icon-192x192.png b/web/embed/static/images/android-icon-192x192.png similarity index 100% rename from web/static/images/android-icon-192x192.png rename to web/embed/static/images/android-icon-192x192.png diff --git a/web/static/images/android-icon-36x36.png b/web/embed/static/images/android-icon-36x36.png similarity index 100% rename from web/static/images/android-icon-36x36.png rename to web/embed/static/images/android-icon-36x36.png diff --git a/web/static/images/android-icon-48x48.png b/web/embed/static/images/android-icon-48x48.png similarity index 100% rename from web/static/images/android-icon-48x48.png rename to web/embed/static/images/android-icon-48x48.png diff --git a/web/static/images/android-icon-72x72.png b/web/embed/static/images/android-icon-72x72.png similarity index 100% rename from web/static/images/android-icon-72x72.png rename to web/embed/static/images/android-icon-72x72.png diff --git a/web/static/images/android-icon-96x96.png b/web/embed/static/images/android-icon-96x96.png similarity index 100% rename from web/static/images/android-icon-96x96.png rename to web/embed/static/images/android-icon-96x96.png diff --git a/web/static/images/apple-icon-114x114.png b/web/embed/static/images/apple-icon-114x114.png similarity index 100% rename from web/static/images/apple-icon-114x114.png rename to web/embed/static/images/apple-icon-114x114.png diff --git a/web/static/images/apple-icon-120x120.png b/web/embed/static/images/apple-icon-120x120.png similarity index 100% rename from web/static/images/apple-icon-120x120.png rename to web/embed/static/images/apple-icon-120x120.png diff --git a/web/static/images/apple-icon-144x144.png b/web/embed/static/images/apple-icon-144x144.png similarity index 100% rename from web/static/images/apple-icon-144x144.png rename to web/embed/static/images/apple-icon-144x144.png diff --git a/web/static/images/apple-icon-152x152.png b/web/embed/static/images/apple-icon-152x152.png similarity index 100% rename from web/static/images/apple-icon-152x152.png rename to web/embed/static/images/apple-icon-152x152.png diff --git a/web/static/images/apple-icon-180x180.png b/web/embed/static/images/apple-icon-180x180.png similarity index 100% rename from web/static/images/apple-icon-180x180.png rename to web/embed/static/images/apple-icon-180x180.png diff --git a/web/static/images/apple-icon-57x57.png b/web/embed/static/images/apple-icon-57x57.png similarity index 100% rename from web/static/images/apple-icon-57x57.png rename to web/embed/static/images/apple-icon-57x57.png diff --git a/web/static/images/apple-icon-60x60.png b/web/embed/static/images/apple-icon-60x60.png similarity index 100% rename from web/static/images/apple-icon-60x60.png rename to web/embed/static/images/apple-icon-60x60.png diff --git a/web/static/images/apple-icon-72x72.png b/web/embed/static/images/apple-icon-72x72.png similarity index 100% rename from web/static/images/apple-icon-72x72.png rename to web/embed/static/images/apple-icon-72x72.png diff --git a/web/static/images/apple-icon-76x76.png b/web/embed/static/images/apple-icon-76x76.png similarity index 100% rename from web/static/images/apple-icon-76x76.png rename to web/embed/static/images/apple-icon-76x76.png diff --git a/web/static/images/apple-icon-precomposed.png b/web/embed/static/images/apple-icon-precomposed.png similarity index 100% rename from web/static/images/apple-icon-precomposed.png rename to web/embed/static/images/apple-icon-precomposed.png diff --git a/web/static/images/apple-icon.png b/web/embed/static/images/apple-icon.png similarity index 100% rename from web/static/images/apple-icon.png rename to web/embed/static/images/apple-icon.png diff --git a/web/static/images/favicon-16x16.png b/web/embed/static/images/favicon-16x16.png similarity index 100% rename from web/static/images/favicon-16x16.png rename to web/embed/static/images/favicon-16x16.png diff --git a/web/static/images/favicon-32x32.png b/web/embed/static/images/favicon-32x32.png similarity index 100% rename from web/static/images/favicon-32x32.png rename to web/embed/static/images/favicon-32x32.png diff --git a/web/static/images/favicon-96x96.png b/web/embed/static/images/favicon-96x96.png similarity index 100% rename from web/static/images/favicon-96x96.png rename to web/embed/static/images/favicon-96x96.png diff --git a/web/static/images/favicon.png b/web/embed/static/images/favicon.png similarity index 100% rename from web/static/images/favicon.png rename to web/embed/static/images/favicon.png diff --git a/web/static/images/loader.gif b/web/embed/static/images/loader.gif similarity index 100% rename from web/static/images/loader.gif rename to web/embed/static/images/loader.gif diff --git a/web/static/images/ms-icon-144x144.png b/web/embed/static/images/ms-icon-144x144.png similarity index 100% rename from web/static/images/ms-icon-144x144.png rename to web/embed/static/images/ms-icon-144x144.png diff --git a/web/static/images/ms-icon-150x150.png b/web/embed/static/images/ms-icon-150x150.png similarity index 100% rename from web/static/images/ms-icon-150x150.png rename to web/embed/static/images/ms-icon-150x150.png diff --git a/web/static/images/ms-icon-310x310.png b/web/embed/static/images/ms-icon-310x310.png similarity index 100% rename from web/static/images/ms-icon-310x310.png rename to web/embed/static/images/ms-icon-310x310.png diff --git a/web/static/images/ms-icon-70x70.png b/web/embed/static/images/ms-icon-70x70.png similarity index 100% rename from web/static/images/ms-icon-70x70.png rename to web/embed/static/images/ms-icon-70x70.png diff --git a/web/static/js/auth.js b/web/embed/static/js/auth.js similarity index 100% rename from web/static/js/auth.js rename to web/embed/static/js/auth.js diff --git a/web/static/js/jquery-3.6.0.min.js b/web/embed/static/js/jquery-3.6.0.min.js similarity index 100% rename from web/static/js/jquery-3.6.0.min.js rename to web/embed/static/js/jquery-3.6.0.min.js diff --git a/web/static/js/quotes.js b/web/embed/static/js/quotes.js similarity index 100% rename from web/static/js/quotes.js rename to web/embed/static/js/quotes.js diff --git a/web/static/js/settings.js b/web/embed/static/js/settings.js similarity index 100% rename from web/static/js/settings.js rename to web/embed/static/js/settings.js diff --git a/web/static/js/tailwind-config.min.js b/web/embed/static/js/tailwind-config.min.js similarity index 100% rename from web/static/js/tailwind-config.min.js rename to web/embed/static/js/tailwind-config.min.js diff --git a/web/static/js/tailwind.3.4.5.es b/web/embed/static/js/tailwind.3.4.5.es similarity index 100% rename from web/static/js/tailwind.3.4.5.es rename to web/embed/static/js/tailwind.3.4.5.es diff --git a/web/static/js/utils.js b/web/embed/static/js/utils.js similarity index 100% rename from web/static/js/utils.js rename to web/embed/static/js/utils.js diff --git a/web/static/service/browserconfig.xml b/web/embed/static/service/browserconfig.xml similarity index 100% rename from web/static/service/browserconfig.xml rename to web/embed/static/service/browserconfig.xml diff --git a/web/static/service/favicon.ico b/web/embed/static/service/favicon.ico similarity index 100% rename from web/static/service/favicon.ico rename to web/embed/static/service/favicon.ico diff --git a/web/static/service/skazanull.webmanifest b/web/embed/static/service/skazanull.webmanifest similarity index 100% rename from web/static/service/skazanull.webmanifest rename to web/embed/static/service/skazanull.webmanifest diff --git a/web/static/webfonts/fa-brands-400.woff2 b/web/embed/static/webfonts/fa-brands-400.woff2 similarity index 100% rename from web/static/webfonts/fa-brands-400.woff2 rename to web/embed/static/webfonts/fa-brands-400.woff2 diff --git a/web/static/webfonts/fa-solid-900.ttf b/web/embed/static/webfonts/fa-solid-900.ttf similarity index 100% rename from web/static/webfonts/fa-solid-900.ttf rename to web/embed/static/webfonts/fa-solid-900.ttf diff --git a/web/static/webfonts/fa-solid-900.woff2 b/web/embed/static/webfonts/fa-solid-900.woff2 similarity index 100% rename from web/static/webfonts/fa-solid-900.woff2 rename to web/embed/static/webfonts/fa-solid-900.woff2 diff --git a/web/templates/auth.html b/web/embed/templates/auth.html similarity index 100% rename from web/templates/auth.html rename to web/embed/templates/auth.html diff --git a/web/templates/head.html b/web/embed/templates/head.html similarity index 100% rename from web/templates/head.html rename to web/embed/templates/head.html diff --git a/web/templates/quotes.html b/web/embed/templates/quotes.html similarity index 100% rename from web/templates/quotes.html rename to web/embed/templates/quotes.html diff --git a/web/templates/settings.html b/web/embed/templates/settings.html similarity index 100% rename from web/templates/settings.html rename to web/embed/templates/settings.html diff --git a/web/go.mod b/web/go.mod index 3105234..f4e1461 100644 --- a/web/go.mod +++ b/web/go.mod @@ -8,6 +8,7 @@ require ( github.com/gin-contrib/sessions v1.0.2 github.com/gin-gonic/gin v1.10.0 github.com/jackc/pgx/v5 v5.7.2 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -46,5 +47,4 @@ require ( golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/protobuf v1.34.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/web/server/server.go b/web/server/server.go index bc683b2..009f4f2 100644 --- a/web/server/server.go +++ b/web/server/server.go @@ -1,7 +1,13 @@ package server import ( + "html/template" + "io/fs" + "log" + "net/http" + "github.com/H1K0/SkazaNull/api" + "github.com/H1K0/SkazaNull/embed" "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" "github.com/gin-gonic/gin" @@ -14,14 +20,19 @@ func Serve(addr string, encryptionKey []byte) { store.Options(sessions.Options{Path: "/"}) r.Use(sessions.Sessions("session", store)) + tmpl := template.Must(template.ParseFS(embed.TemplatesFS, "templates/*.html")) + r.SetHTMLTemplate(tmpl) + api.RegisterRoutes(r) - r.LoadHTMLGlob("templates/*.html") - - r.Static("/favicon.ico", "./static/service/favicon.ico") - r.Static("/skazanull.webmanifest", "./static/service/skazanull.webmanifest") - r.Static("/browserconfig.xml", "./static/service/browserconfig.xml") - r.Static("/static", "./static") + static, err := fs.Sub(embed.StaticFS, "static") + if err != nil { + log.Fatalf("Failed to get subs of embedded static FS: %s\n", err) + } + r.StaticFS("/static/", http.FS(static)) + r.StaticFileFS("/favicon.ico", "static/service/favicon.ico", http.FS(embed.StaticFS)) + r.StaticFileFS("/skazanull.webmanifest", "static/service/skazanull.webmanifest", http.FS(embed.StaticFS)) + r.StaticFileFS("/browserconfig.xml", "static/service/browserconfig.xml", http.FS(embed.StaticFS)) r.GET("/", api.MiddlewareAuth, root) r.GET("/quotes", api.MiddlewareAuth, middlewareAuth, quotes)