Default to SQLite rather than Postgres & Redis (#72)
* Initial rough draft switch to sqlite. * Rewrote cache implemenation. * Provide typed tasks. * Task cleanup. * Use same db for tasks. * Provide task queue registration and service container injection. * Added optional delay to tasks. Pool buffers when encoding. * Added tests for the task client and runner. * Added handler examples for caching and tasks. * Cleanup and documentation. * Use make in workflow. * Updated documentation. * Updated documentation.
This commit is contained in:
parent
5e9e502b42
commit
a096abd195
29 changed files with 956 additions and 910 deletions
|
|
@ -28,6 +28,8 @@
|
|||
<li>{{link (url "home") "Dashboard" .Path}}</li>
|
||||
<li>{{link (url "about") "About" .Path}}</li>
|
||||
<li>{{link (url "contact") "Contact" .Path}}</li>
|
||||
<li>{{link (url "cache") "Cache" .Path}}</li>
|
||||
<li>{{link (url "task") "Task" .Path}}</li>
|
||||
</ul>
|
||||
|
||||
<p class="menu-label">Account</p>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<p>Warning</p>
|
||||
</div>
|
||||
<div class="message-body">
|
||||
This route has caching enabled so hot-reloading in the local environment will not work. Check the Redis cache for a key matching the URL path.
|
||||
This route has caching enabled so hot-reloading in the local environment will not work.
|
||||
</div>
|
||||
</article>
|
||||
{{- end}}
|
||||
|
|
|
|||
36
templates/pages/cache.gohtml
Normal file
36
templates/pages/cache.gohtml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{{define "content"}}
|
||||
<form id="task" method="post" hx-post="{{url "cache.submit"}}">
|
||||
<article class="message">
|
||||
<div class="message-header">
|
||||
<p>Test the cache</p>
|
||||
</div>
|
||||
<div class="message-body">
|
||||
This route handler shows how the default in-memory cache works. Try updating the value using the form below and see how it persists after you reload the page.
|
||||
HTMX makes it easy to re-render the cached value after the form is submitted.
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<label for="value" class="label">Value in cache: </label>
|
||||
{{if .Data}}
|
||||
<span class="tag is-success">{{.Data}}</span>
|
||||
{{- else}}
|
||||
<i>(empty)</i>
|
||||
{{- end}}
|
||||
<br/><br/>
|
||||
|
||||
<div class="field">
|
||||
<label for="value" class="label">Value</label>
|
||||
<div class="control">
|
||||
<input id="value" name="value" class="input" value="{{.Form.Value}}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
<button class="button is-link">Update cache</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "csrf" .}}
|
||||
</form>
|
||||
{{end}}
|
||||
43
templates/pages/task.gohtml
Normal file
43
templates/pages/task.gohtml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{{define "content"}}
|
||||
{{- if not (eq .HTMX.Request.Target "task")}}
|
||||
<article class="message is-link">
|
||||
<div class="message-body">
|
||||
<p>Submitting this form will create an <i>ExampleTask</i> in the task queue. After the specified delay, the message will be logged by the queue processor.</p>
|
||||
<p>See pkg/tasks and the README for more information.</p>
|
||||
</div>
|
||||
</article>
|
||||
{{- end}}
|
||||
|
||||
{{template "form" .}}
|
||||
{{end}}
|
||||
|
||||
{{define "form"}}
|
||||
<form id="task" method="post" hx-post="{{url "task.submit"}}">
|
||||
{{template "messages" .}}
|
||||
<div class="field">
|
||||
<label for="delay" class="label">Delay (in seconds)</label>
|
||||
<div class="control">
|
||||
<input type="number" id="delay" name="delay" class="input {{.Form.GetFieldStatusClass "Delay"}}" value="{{.Form.Delay}}"/>
|
||||
</div>
|
||||
<p class="help">How long to wait until the task is executed</p>
|
||||
{{template "field-errors" (.Form.GetFieldErrors "Delay")}}
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="message" class="label">Message</label>
|
||||
<div class="control">
|
||||
<textarea id="message" name="message" class="textarea {{.Form.GetFieldStatusClass "Message"}}">{{.Form.Message}}</textarea>
|
||||
</div>
|
||||
<p class="help">The message the task will output to the log</p>
|
||||
{{template "field-errors" (.Form.GetFieldErrors "Message")}}
|
||||
</div>
|
||||
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
<button class="button is-link">Add task to queue</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "csrf" .}}
|
||||
</form>
|
||||
{{end}}
|
||||
|
|
@ -22,6 +22,7 @@ const (
|
|||
|
||||
const (
|
||||
PageAbout Page = "about"
|
||||
PageCache Page = "cache"
|
||||
PageContact Page = "contact"
|
||||
PageError Page = "error"
|
||||
PageForgotPassword Page = "forgot-password"
|
||||
|
|
@ -30,6 +31,7 @@ const (
|
|||
PageRegister Page = "register"
|
||||
PageResetPassword Page = "reset-password"
|
||||
PageSearch Page = "search"
|
||||
PageTask Page = "task"
|
||||
)
|
||||
|
||||
//go:embed *
|
||||
|
|
@ -41,7 +43,7 @@ func Get() embed.FS {
|
|||
}
|
||||
|
||||
// GetOS returns a file system containing all templates which will load the files directly from the operating system.
|
||||
// This should only be used for local development in order to faciliate live reloading.
|
||||
// This should only be used for local development in order to facilitate live reloading.
|
||||
func GetOS() fs.FS {
|
||||
// Gets the complete templates directory path
|
||||
// This is needed in case this is called from a package outside of main, such as within tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue