Documentation
¶
Overview ¶
Package ui serves taskmill's web interface: a 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 interface is rendered on the server with the standard library. A small script, served with it, keeps pages live and adds dialogs; every page also works without it, and nothing needs a JavaScript build step. It 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:
mux.Handle("/taskmill/", auth(ui.Handler(client, &ui.Config{Prefix: "/taskmill"})))
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 Handler ¶
Handler returns the web interface for client. cfg may be nil. Handler panics 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 web interface 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
mux := http.NewServeMux()
mux.Handle("/taskmill/", requireAdmin(ui.Handler(client, &ui.Config{Prefix: "/taskmill"})))
server := &http.Server{Addr: "localhost:8080", Handler: mux, ReadHeaderTimeout: 10 * time.Second}
log.Fatal(server.ListenAndServe())
}
Output:
Example (Dashboard) ¶
This example serves the web interface as a dashboard of 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 := ui.Handler(client, &ui.Config{
BasicAuth: &ui.BasicAuth{Username: "ops", Password: "a long random password"},
FrameAncestors: []string{"https://admin.example.com"},
})
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 interface 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
// interface in a frame, such as "https://admin.example.com", or "'self'"
// for the application's own pages. Default: none; the interface cannot be
// framed, which protects it from clickjacking.
FrameAncestors []string
// Logger receives every action taken, and the errors that the interface
// shows as a server error. Default: logs are discarded.
Logger *slog.Logger
}
Config configures the web interface. The zero value is valid.