Documentation
¶
Overview ¶
Package timeclock tracks time for payroll: clocking in and out, time by project and customer, vacation and sick time per pay cycle, timesheets, approvals, exceptions and reports a payroll system can import.
It runs inside a host application, which mounts Timeclock under a path, tells it who is calling and answers its questions about people through a host.Directory:
tc, err := timeclock.New(ctx, timeclock.Options{
DatabaseURL: dsn,
BasePath: "/timeclock",
Caller: func(r *http.Request) (string, bool) { return userIDFromSession(r) },
Directory: directory,
})
go tc.Run(ctx)
mux.Handle("/timeclock/", tc)
cmd/timeclock-server runs it on its own, with its own sign-in.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// DatabaseURL is the PostgreSQL database holding Timeclock's schema,
// normally the host's own.
DatabaseURL string
// Schema is Timeclock's schema in that database. Defaults to "timeclock".
Schema string
// SkipMigrations leaves migrating to the host. By default New applies
// Timeclock's migrations under an advisory lock, so replicas can start
// together.
SkipMigrations bool
// BasePath is where the host mounts Timeclock, such as "/timeclock".
// Requests reach Timeclock with it still on the path. Empty serves at
// the root.
BasePath string
// Caller returns the host user making a request, from the host's
// session or API key.
Caller func(r *http.Request) (userID string, ok bool)
// Directory answers questions about the host's people.
Directory host.Directory
// Notifier delivers reminders (a clock left running, a timesheet that is
// due) through the host's notifications. Without one, none are sent.
Notifier host.Notifier
// HomeURL and HomeLabel link from Timeclock back to the host, such as
// "/" and the host's name.
HomeURL string
HomeLabel string
// SignInURL is where the host signs a person in, ending with the query
// parameter that takes the path to return to, such as "/login?next=".
// Timeclock's web app sends a signed-out browser there.
SignInURL string
// SignOutURL is the host's same-origin endpoint that ends its session.
// Timeclock's web app POSTs to it and then loads HomeURL. Without it,
// Timeclock offers no sign-out.
SignOutURL string
// AccountsURL is where a standalone server manages its own accounts
// (workspaces to switch between, invitations, passwords). A host that
// has its own users leaves it empty.
AccountsURL string
// ThemeStorageKey is the localStorage key where the host keeps the
// person's light, dark or system choice, so Timeclock matches it.
// Without it, Timeclock follows the system.
ThemeStorageKey string
// Workspace names the workspace a request is in, for a host with more
// than one organization: each key is its own people, time and settings,
// made the first time it is seen. Without it, everyone is in one.
Workspace func(r *http.Request) (key string, ok bool)
// Theme is the host's look, so Timeclock mounted in it matches: for
// light and for dark, an accent and a background. A workspace admin can
// still set the workspace's own in Timeclock's settings.
Theme host.Theme
// Routes registers extra handlers beside Timeclock's own, such as a
// standalone server's sign-in.
Routes func(mux *http.ServeMux)
// DevServer is the Vite dev server, such as "http://localhost:5174",
// proxied while the module embeds no web build.
DevServer string
// HSTS sends Strict-Transport-Security. A host that sets its own
// security headers leaves it off.
HSTS bool
// Logger defaults to slog.Default().
Logger *slog.Logger
}
Options configures a Timeclock.
type Timeclock ¶
type Timeclock struct {
// contains filtered or unexported fields
}
Timeclock is an http.Handler for everything under its base path, and background work started by Run.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
timeclock-server
command
Command timeclock-server runs Timeclock on its own, with its own accounts.
|
Command timeclock-server runs Timeclock on its own, with its own accounts. |
|
examples
|
|
|
host
command
Command host is the smallest application that has Timeclock inside it: it mounts Timeclock under /timeclock, says who is calling and which of its organizations they are in, and gives Timeclock its own colors.
|
Command host is the smallest application that has Timeclock inside it: it mounts Timeclock under /timeclock, says who is calling and which of its organizations they are in, and gives Timeclock its own colors. |
|
Package host defines what a platform embedding Timeclock tells it about its people and, optionally, how to reach them.
|
Package host defines what a platform embedding Timeclock tells it about its people and, optionally, how to reach them. |
|
internal
|
|
|
api
Package api is Timeclock's HTTP API, defined with huma.
|
Package api is Timeclock's HTTP API, defined with huma. |
|
clock
Package clock is Timeclock's payroll logic and storage: pay periods, time entries, time off, timesheets, approvals, exceptions and reports.
|
Package clock is Timeclock's payroll logic and storage: pay periods, time entries, time off, timesheets, approvals, exceptions and reports. |
|
standalone
Package standalone gives a Timeclock that runs on its own what a host would: accounts with a password, the workspaces each belongs to, sessions, invitations and password resets by email, optional sign-in with an OpenID Connect provider, and a directory of each workspace's people.
|
Package standalone gives a Timeclock that runs on its own what a host would: accounts with a password, the workspaces each belongs to, sessions, invitations and password resets by email, optional sign-in with an OpenID Connect provider, and a directory of each workspace's people. |
|
Package migrations embeds Timeclock's SQL schema migrations, applied with goose.
|
Package migrations embeds Timeclock's SQL schema migrations, applied with goose. |
|
Package web embeds the compiled Vite frontend.
|
Package web embeds the compiled Vite frontend. |
Click to show internal directories.
Click to hide internal directories.