API
Every exported symbol of github.com/gsandoval/tako, from the
same lock file the API-freeze test compares against — so this page cannot quietly
lose one. Everything under pkg/… is tako's internals and is not here.
HTTP
tako.API
func API[Req, Res any](route string, fn func(Ctx, Req) (Res, error), cfg ...Route) Endpoint[Req, Res]func Errorf(status int, format string, args ...any) errorfunc IsNotFound(err error) boolfunc NotFound() errortype Client struct{IP string; UserAgent string}type Ctx interface{Client() Client; IsHTMX() bool; Log() *log/slog.Logger; MaybeUser() (User, bool); Task() (index int, count int); User() User; context.Context}func (Ctx).Client() Clientfunc (Ctx).IsHTMX() boolfunc (Ctx).Log() *log/slog.Loggerfunc (Ctx).MaybeUser() (User, bool)func (Ctx).Task() (index int, count int)func (Ctx).User() Userfunc (context.Context).Deadline() (deadline time.Time, ok bool)func (context.Context).Done() <-chan struct{}func (context.Context).Err() errorfunc (context.Context).Value(key any) anytype Route struct{SignIn bool; Allow *PolicyHandle; Private bool; MaxAge time.Duration}
tako.Page
func Page[Req any](route string, fn func(Ctx, Req) (HTML, error), cfg ...Route) Endpoint[Req, HTML]func Redirect(target string) (HTML, error)func RedirectPermanent(target string) (HTML, error)type HTML struct{}
tako.Site
func Site(dir string, cfg ...SiteConfig) *SiteHandlefunc StatusPage(fn func(Ctx, Status) (HTML, error)) StatusHandletype Build struct{Command string; Out string}type SiteConfig struct{SPA bool; Build Build; DevProxy string; Redirects map[string]string; TrustedHTML bool; NotFound string}type SiteHandle struct{}func (*SiteHandle).Fragment(ctx Ctx, template string, data any) (HTML, error)func (*SiteHandle).Markdown(ctx Ctx, src string) (HTML, error)func (*SiteHandle).PrepareTemplates(ctx Ctx, fsys io/fs.FS) (*TemplateSet, error)func (*SiteHandle).Render(ctx Ctx, template string, data any) (HTML, error)func (*SiteHandle).UseTemplates(ctx Ctx, set *TemplateSet) errortype Status struct{Code int; Path string; RequestID string; Message string; Policy string}type StatusHandle struct{}func (StatusHandle).Declared() boolfunc (StatusHandle).Render(ctx Ctx, s Status) (HTML, error)type TemplateErrors struct{Failed map[string]string}func (*TemplateErrors).Error() stringtype TemplateSet struct{}func (*TemplateSet).Fragment(ctx Ctx, template string, data any) (HTML, error)func (*TemplateSet).Render(ctx Ctx, template string, data any) (HTML, error)
tako.Service
const EnvCloud Envconst EnvLocal Envfunc Environment() Envfunc Service(cfg ...ServiceConfig) *ServiceHandletype Env intfunc (Env).String() stringtype ServiceConfig struct{Domain string; Profile Profile; Footprint Footprint; Traffic Traffic}type ServiceHandle struct{}func (*ServiceHandle).Domain() string
Data
tako.Entity — typed entity stores
func Entity[T any](name string) *EntityHandle[T]func NewID() stringtype EntityHandle[T any] struct{}func (*EntityHandle[T]).Delete(ctx Ctx, id string) errorfunc (*EntityHandle[T]).Exists(ctx Ctx, id string) (bool, error)func (*EntityHandle[T]).Get(ctx Ctx, id string) (T, error)func (*EntityHandle[T]).Put(ctx Ctx, entity T) errorfunc (*EntityHandle[T]).Query(ctx Ctx) *EntityQuery[T]func (*EntityHandle[T]).Tx(ctx Ctx, fn func(tx EntityTx[T]) error) errorfunc (*EntityHandle[T]).Update(ctx Ctx, id string, mutate func(*T)) errortype EntityPage[T any] struct{Items []T; Cursor string; More bool}type EntityQuery[T any] struct{}func (*EntityQuery[T]).All() ([]T, error)func (*EntityQuery[T]).Count() (int64, error)func (*EntityQuery[T]).First() (T, error)func (*EntityQuery[T]).Iter() Iter[T]func (*EntityQuery[T]).Limit(n int) *EntityQuery[T]func (*EntityQuery[T]).OrderBy(field string) *EntityQuery[T]func (*EntityQuery[T]).Page(cursor string) (EntityPage[T], error)func (*EntityQuery[T]).Where(field string, op string, value any) *EntityQuery[T]type EntityTx[T any] interface{Delete(id string) error; Get(id string) (T, error); Put(entity T) error}func (EntityTx[T any]).Delete(id string) errorfunc (EntityTx[T any]).Get(id string) (T, error)func (EntityTx[T any]).Put(entity T) errortype Iter[T any] struct{}func (*Iter[T]).Err() errorfunc (*Iter[T]).Next() (T, bool)
tako.Cache — per-instance TTL cache
func Cache[T any](name string, ttl time.Duration) *CacheHandle[T]type CacheHandle[T any] struct{}func (*CacheHandle[T]).Delete(ctx Ctx, key string) errorfunc (*CacheHandle[T]).Exists(ctx Ctx, key string) (bool, error)func (*CacheHandle[T]).Get(ctx Ctx, key string) (T, error)func (*CacheHandle[T]).GetOrFill(ctx Ctx, key string, fill func(Ctx) (T, error)) (T, error)func (*CacheHandle[T]).Put(ctx Ctx, key string, value T) error
tako.Secret, metrics, and tako logs
func Counter(name string) *CounterHandlefunc Histogram(name string) *HistogramHandlefunc Secret(name string) *SecretHandletype CounterHandle struct{}func (*CounterHandle).Add(ctx Ctx, delta int64)func (*CounterHandle).Count() Metricfunc (*CounterHandle).Rate() Metrictype HistogramHandle struct{}func (*HistogramHandle).Count() Metricfunc (*HistogramHandle).Mean() Metricfunc (*HistogramHandle).Observe(ctx Ctx, value float64)func (*HistogramHandle).Percentile(q float64) Metricfunc (*HistogramHandle).Rate() Metricfunc (*HistogramHandle).Sum() Metrictype SecretHandle struct{}func (*SecretHandle).Value() string
tako.Alert — conditions, channels, and who gets woken up
func Alert(when Condition, notify *ChannelHandle, also ...*ChannelHandle) AlertHandlefunc AlertEmail(address string) *ChannelHandlefunc AlertTopic[T any](topic *TopicHandle[T]) *ChannelHandlefunc AlertWebhook(url string) *ChannelHandlefunc CronFailed(cron Handler, times int, w ...Window) Conditionfunc CronMissed(cron Handler, w ...Window) Conditionfunc JobFailed[T any](job *JobHandle[T], times int, w ...Window) Conditionfunc PlatformMetric(metricType string, filters ...string) Metricfunc QueueBacklogged(c Consumer, n int, w QueueWatch) Conditionfunc QueueMetric(c Consumer, metricType string, filters ...string) Metricfunc QueueStalled(c Consumer, age time.Duration, w QueueWatch) Conditionfunc RequestMs(t Target) *RequestMsHandlefunc Requests(t Target) *RequestsHandlefunc RequestsErroring(t Target, fraction float64, w ...Window) Conditionfunc RequestsSlow(t Target, d time.Duration, quantile float64, w ...Window) Conditionfunc ServiceAtCapacity(t Target, w ...Window) Conditionfunc ServiceInstances(t Target) Metricfunc ServiceMetric(t Target, metricType string, filters ...string) Metricfunc ServicePercentile(t Target, metricType string, q float64, filters ...string) Metricfunc SingletonDown(loop Handler, w ...Window) Conditionfunc WhenAbove(m Metric, threshold float64, w Window) Conditionfunc WhenAbsent(m Metric, w Window) Conditionfunc WhenAtLeast(m Metric, n float64, w Window) Conditionfunc WhenBelow(m Metric, threshold float64, w Window) Conditiontype AlertHandle struct{}type ChannelHandle struct{}type Condition struct{}type Consumer interface{consumerRef() metricRef}type Metric interface{metricSubject() metricRef}type QueueWatch struct{DeadLetters bool; For time.Duration}type RequestMsHandle struct{}func (*RequestMsHandle).Count() Metricfunc (*RequestMsHandle).Mean() Metricfunc (*RequestMsHandle).Percentile(q float64) Metricfunc (*RequestMsHandle).Rate() Metricfunc (*RequestMsHandle).Sum() Metrictype RequestsHandle struct{}func (*RequestsHandle).Count() Metricfunc (*RequestsHandle).Fraction() Metricfunc (*RequestsHandle).Rate() Metricfunc (*RequestsHandle).Status(class string) *RequestsHandletype Target interface{alertTarget() metricRef}type Window struct{For time.Duration; Every time.Duration}
Async
tako.Queue + tako.Worker — at-least-once work
func Permanent(err error) errorfunc Queue[T any](name string, cfg ...Delivery) *QueueHandle[T]func Worker[T any](queue *QueueHandle[T], fn func(Ctx, T) error, cfg ...Compute) Handlertype Delivery struct{MaxAttempts int; MinBackoff time.Duration; MaxBackoff time.Duration; RateLimit int}type QueueHandle[T any] struct{}func (*QueueHandle[T]).Publish(ctx Ctx, msg T) errorfunc (*QueueHandle[T]).PublishAfter(ctx Ctx, msg T, delay time.Duration) error
tako.Topic + tako.Subscribe — fan-out events
func Subscribe[T any](source EventSource[T], fn func(Ctx, T) error, cfg ...Compute) Handlerfunc Topic[T any](name string, cfg ...Delivery) *TopicHandle[T]type EventSource[T any] interface{eventSource(T); sourceName() string}type TopicHandle[T any] struct{}func (*TopicHandle[T]).Publish(ctx Ctx, event T) error
tako.Bucket — blobs, signed URLs, upload events
func Bucket(name string) *BucketHandletype Blob struct{Reader io.Reader; ContentType string; Size int64; ETag string}type BucketEvent struct{}type BucketHandle struct{Uploaded BucketEvent}func (*BucketHandle).Delete(ctx Ctx, key string) errorfunc (*BucketHandle).Exists(ctx Ctx, key string) (bool, error)func (*BucketHandle).Get(ctx Ctx, key string) (Blob, error)func (*BucketHandle).List(ctx Ctx, prefix string) Iter[ObjectInfo]func (*BucketHandle).Put(ctx Ctx, key string, blob Blob) errorfunc (*BucketHandle).SignedGet(ctx Ctx, key string, ttl time.Duration) (string, error)func (*BucketHandle).SignedPut(ctx Ctx, key string, ttl time.Duration, policy ...PutPolicy) (string, error)type ObjectInfo struct{Key string; Size int64; ContentType string; Updated time.Time}type PutPolicy struct{MaxSize int64; ContentType string}func (PutPolicy).Headers() map[string]string
tako.Cron — scheduled handlers
func Cron(schedule string, fn func(Ctx) error, cfg ...CronConfig) Handlertype CronConfig struct{Singleflight bool; Timezone string; Deadline time.Duration; Profile Profile; Footprint Footprint}
tako.Lock — distributed leases
func Lock(name string) *LockHandletype LockHandle struct{}func (*LockHandle).Do(ctx Ctx, fn func(Ctx) error) errorfunc (*LockHandle).TryDo(ctx Ctx, fn func(Ctx) error) (bool, error)
tako.Handler — what a background declaration returns
type Handler struct{}
Compute
job.md — tako.Job + tako.Runner
func Job[T any](name string) *JobHandle[T]func Runner[T any](job *JobHandle[T], fn func(Ctx, T) error, cfg ...RunnerConfig) Handlertype JobHandle[T any] struct{}func (*JobHandle[T]).Run(ctx Ctx, params T) errortype RunnerConfig struct{Parallel int; Attempts int; Timeout time.Duration; Profile Profile; Footprint Footprint}
singleton.md — tako.Singleton
func Singleton(fn func(Ctx) error, cfg ...SingletonConfig) Handlertype SingletonConfig struct{Timeout time.Duration; Footprint Footprint}
calls.md — cross-service calls
type Endpoint[Req any, Res any] struct{}func (Endpoint[Req, Res]).Call(ctx Ctx, req Req) (Res, error)
footprint.md — the Profile and Footprint fields
const ProfileBatch Profileconst ProfileDefault Profileconst ProfileLatency Profileconst ToggleInherit Toggleconst ToggleOff Toggleconst ToggleOn Toggletype Compute struct{Profile Profile; Footprint Footprint; Traffic Traffic}type Footprint struct{CPU int; Memory string; Concurrency int; MinInstances int; MaxInstances int; CPUAlwaysOn Toggle; StartupBoost Toggle}type Profile inttype Toggle inttype Traffic struct{Timeout time.Duration; SessionAffinity Toggle; HTTP2 Toggle}
Edges
tako.Auth — providers, sessions, Route.SignIn, the dev bar
func Auth(cfg AuthConfig) *AuthHandlefunc Deny(msg string) errorfunc IsDenied(err error) boolfunc IsEmailTaken(err error) boolfunc Policy(fn func(Ctx, User) error) *PolicyHandlefunc RequireRole(roles ...RoleHandle) *PolicyHandlefunc Role(name string) RoleHandletype AuthConfig struct{Google bool; Password bool}type AuthEvent struct{}type AuthHandle struct{Registered AuthEvent; FirstSignIn AuthEvent}func (*AuthHandle).Users() *UsersHandletype NewUser struct{Email string; Password string; Name string; Roles []string}type PolicyHandle struct{}func (*PolicyHandle).Check(ctx Ctx, u User) errorfunc (*PolicyHandle).Roles() []stringtype RoleHandle struct{}func (RoleHandle).Name() stringtype User struct{ID string; Email string; Name string; Provider string; Roles []string; EmailVerified bool}func (User).HasRole(role RoleHandle) booltype UserQuery struct{}func (*UserQuery).Limit(n int) *UserQueryfunc (*UserQuery).Page(cursor string) (UsersPage, error)type UsersHandle struct{}func (*UsersHandle).ByEmail(ctx Ctx, email string) (User, error)func (*UsersHandle).Create(ctx Ctx, spec NewUser) (User, error)func (*UsersHandle).Delete(ctx Ctx, id string) errorfunc (*UsersHandle).Disable(ctx Ctx, id string) errorfunc (*UsersHandle).Enable(ctx Ctx, id string) errorfunc (*UsersHandle).Get(ctx Ctx, id string) (User, error)func (*UsersHandle).Grant(ctx Ctx, id string, role RoleHandle) errorfunc (*UsersHandle).List(ctx Ctx) *UserQueryfunc (*UsersHandle).Revoke(ctx Ctx, id string, role RoleHandle) errortype UsersPage struct{Users []User; Next string}
tako.NewTestApp: testing an app
func NewTestApp(tb testing.TB) *TestApptype TestApp struct{}func (*TestApp).Advance(d time.Duration)func (*TestApp).AdvanceCron(cron Handler)func (*TestApp).Chaos()func (*TestApp).Ctx(as ...User) Ctxfunc (*TestApp).DrainQueues()func (*TestApp).HTMX(as ...User) Ctxfunc (*TestApp).Handler() net/http.Handlerfunc (*TestApp).SetSecret(name string, value string)func (*TestApp).SignIn(name string, roles ...RoleHandle) User