From 1135e519b9b998b70960cab78b721573c70da986 Mon Sep 17 00:00:00 2001 From: Johan Lindh Date: Wed, 18 Dec 2024 09:32:41 +0100 Subject: [PATCH] docs --- jawsboot/README.md | 25 +++++++++++++++++++++++++ staticserve/README.md | 6 ++++++ staticserve/staticserve.go | 6 +++--- templatereloader/README.md | 7 +++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 jawsboot/README.md create mode 100644 staticserve/README.md create mode 100644 templatereloader/README.md diff --git a/jawsboot/README.md b/jawsboot/README.md new file mode 100644 index 0000000..cf201c6 --- /dev/null +++ b/jawsboot/README.md @@ -0,0 +1,25 @@ +# jawsboot + +Provides a statically served and embedded version of [Bootstrap](https://getbootstrap.com/). + +Example usage that loads your templates, favicon and Bootstrap. Also uses the templatereloader +so that when running with `-tags debug` or `-race` templates are reloaded from disk as needed. + +```go +//go:embed assets +var assetsFS embed.FS + +func setupRoutes(jw *jaws.Jaws, mux *http.ServeMux) (err error) { + var tmpl jaws.TemplateLookuper + if tmpl, err = templatereloader.New(assetsFS, "assets/ui/*.html", ""); err == nil { + jw.AddTemplateLookuper(tmpl) + var faviconuri string + if faviconuri, err = staticserve.HandleFS(assetsFS, "assets", "static/images/favicon.png", mux.Handle); err == nil { + if err = jawsboot.Setup(jw, mux.Handle, faviconuri); err == nil { + // set up your other routes + } + } + } + return +} +``` diff --git a/staticserve/README.md b/staticserve/README.md new file mode 100644 index 0000000..3c96871 --- /dev/null +++ b/staticserve/README.md @@ -0,0 +1,6 @@ +# staticserve + +`staticserve` is a cache-busting HTTP handler for static files. It supports +GET operations requesting the file with no encoding or gzip encoding. + +For an example how to use it, see `jawsboot/README.md`. \ No newline at end of file diff --git a/staticserve/staticserve.go b/staticserve/staticserve.go index 7445d70..72f123e 100644 --- a/staticserve/staticserve.go +++ b/staticserve/staticserve.go @@ -11,9 +11,9 @@ import ( ) type StaticServe struct { - Name string - ContentType string - Gz []byte + Name string // the cache-busting file name, e.g. "static/filename.1234567.js" + ContentType string // Content-Type of the file, e.g. "application/javascript" + Gz []byte // gzipped data, will be unpacked as needed } // New returns a StaticServe that serves the given data with a filename like 'filename.12345678.ext'. diff --git a/templatereloader/README.md b/templatereloader/README.md new file mode 100644 index 0000000..25fd060 --- /dev/null +++ b/templatereloader/README.md @@ -0,0 +1,7 @@ +# templatereloader + +A templatereloader is a `jaws.TemplateLookuper` that will reload templates from +disk as needed if running with `-tags debug` or `-race`. If not, it simply calls +`template.New("").ParseFS(fsys, fpath)` and has no overhead. + +For example usage, see `jawsboot/README.md`