admin

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 7 Imported by: 0

README

Admin Ops Middleware

What it does

Registers protected operational endpoints for runtime information, route inspection, queue statistics, queue job listing, and failed-job retry/discard operations.

How to implement

package main

import (
	"github.com/oarkflow/fh"
	"github.com/oarkflow/fh/mw/admin"
)

func main() {
	app := fh.New()
	admin.Enable(app, admin.Config{
		Prefix: "/_fh/admin",
		Auth: admin.StaticToken("X-Admin-Token", "change-me"),
	})

	app.Get("/", func(c fh.Ctx) error { return c.Status(fh.StatusOK).SendString("ok") })
}

Impact

Adds an operations plane that makes production debugging and queue recovery easier. The impact is negligible unless admin routes are called.

Ordering guidance

Register after the app is created and after queue/runtime features are configured. Do not expose before security controls are decided.

Production considerations

Always protect with mTLS, VPN/private network, IP allowlist, or strong token auth. Rotate admin tokens and audit every admin call. Never expose debug or queue mutation endpoints publicly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enable

func Enable(app *fh.App, cfg Config) *fh.App

Types

type AuditFunc

type AuditFunc func(ctx fh.Ctx, action string, allowed bool)

type AuthFunc

type AuthFunc func(fh.Ctx) bool

func StaticToken

func StaticToken(header, token string) AuthFunc

type Config

type Config struct {
	Prefix  string
	Auth    AuthFunc
	Timeout time.Duration
	// AllowInsecure disables all authentication and IP allowlisting for admin
	// endpoints. This exposes runtime introspection (goroutines, routes, queue
	// internals) to any client that can reach the server. NEVER enable this in
	// production or on a network reachable from untrusted clients.
	AllowInsecure bool
	AllowedIPs    []string
	Audit         AuditFunc
}

Jump to

Keyboard shortcuts

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