Documentation
¶
Overview ¶
Package ui serves taskmill's dashboard of queues, tasks, schedules, and workers, with actions to pause and resume queues and schedules, run a schedule now, and retry, cancel, and delete tasks, one at a time or all that match the task list's filters.
The dashboard is rendered on the server with the standard library. Two small scripts, served with it, keep pages live, apply filters as they change, confirm actions in dialogs, and apply the chosen theme. Every page also works without them, and nothing needs a JavaScript build step. The dashboard reads only through the bounded queries of taskmill.Client, so it is safe to point at a busy production database.
Mount it in an application, behind the application's own authentication:
dashboard, err := ui.New(client, &ui.Config{Prefix: "/taskmill"})
// ...
mux.Handle("/taskmill/", auth(dashboard))
Or protect it with Config.BasicAuth, for example when the command github.com/code19m/taskmill/cmd/taskmill-ui serves it as a dashboard of its own. Another web application can show it in a frame once its origin is listed in Config.FrameAncestors.
Actions are protected against cross-site request forgery with http.CrossOriginProtection, and Config.ReadOnly disables them entirely.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶ added in v0.3.0
New returns the dashboard for client. cfg may be nil. It returns an error that wraps taskmill.ErrInvalidArgument if client is nil, if cfg.Prefix does not start with a slash, if cfg.BasicAuth has an empty username or password, or if an entry of cfg.FrameAncestors is empty or holds a space, comma, or semicolon.
Example ¶
This example mounts the dashboard under /taskmill, behind the application's own authentication.
package main
import (
"log"
"net/http"
"time"
"github.com/code19m/taskmill"
"github.com/code19m/taskmill/ui"
)
func requireAdmin(next http.Handler) http.Handler { return next }
func main() {
var client *taskmill.Client // from taskmill.NewClient
dashboard, err := ui.New(client, &ui.Config{Prefix: "/taskmill"})
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/taskmill/", requireAdmin(dashboard))
server := &http.Server{Addr: "localhost:8080", Handler: mux, ReadHeaderTimeout: 10 * time.Second}
log.Fatal(server.ListenAndServe())
}
Output:
Example (Dashboard) ¶
This example serves the dashboard on its own, with a password, and lets the company's admin panel show it in a frame.
package main
import (
"log"
"net/http"
"time"
"github.com/code19m/taskmill"
"github.com/code19m/taskmill/ui"
)
func main() {
var client *taskmill.Client // from taskmill.NewClient
handler, err := ui.New(client, &ui.Config{
BasicAuth: &ui.BasicAuth{Username: "ops", Password: "a long random password"},
FrameAncestors: []string{"https://admin.example.com"},
})
if err != nil {
log.Fatal(err)
}
server := &http.Server{Addr: ":8443", Handler: handler, ReadHeaderTimeout: 10 * time.Second}
log.Fatal(server.ListenAndServeTLS("cert.pem", "key.pem"))
}
Output:
Types ¶
type Config ¶
type Config struct {
// Prefix is the path the handler is mounted at, such as "/taskmill".
// The handler strips it from requests and adds it to links and
// redirects, so do not wrap the handler in http.StripPrefix.
// Default: none, the root.
Prefix string
// ReadOnly hides and refuses every action that changes state.
ReadOnly bool
// BasicAuth, if set, requires every request to log in with HTTP basic
// authentication. Serve the dashboard over HTTPS when it is set: basic
// authentication sends the password with every request. Default: none;
// the application in front of the handler authenticates.
BasicAuth *BasicAuth
// FrameAncestors lists the origins of the pages that may show the
// dashboard in a frame, such as "https://admin.example.com", or "'self'"
// for the application's own pages. Default: none; the dashboard cannot be
// framed, which protects it from clickjacking.
FrameAncestors []string
// Logger receives every action taken, and the errors that the dashboard
// shows as a server error. Default: logs are discarded.
Logger *slog.Logger
}
Config configures the dashboard. The zero value is valid.