ui

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 25 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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:

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

func New(client *taskmill.Client, cfg *Config) (http.Handler, error)

New returns the web interface 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 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
	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())
}
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, 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"))
}

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth is the one user that may use the interface.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL