middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS(next http.Handler) http.Handler

CORS is middleware that sets permissive CORS headers.

func DevIdentity

func DevIdentity(next http.Handler) http.Handler

DevIdentity is middleware that sets a development user identity (user_id=1).

func RequestLogging

func RequestLogging(log *slog.Logger) func(http.Handler) http.Handler

RequestLogging returns middleware that logs HTTP requests.

func TailscaleIdentity

func TailscaleIdentity(lc WhoisClient, db UserStore, log *slog.Logger) func(http.Handler) http.Handler

TailscaleIdentity returns middleware that authenticates requests via Tailscale WhoIs.

func UserIDFromContext

func UserIDFromContext(r *http.Request) (int, bool)

UserIDFromContext returns the authenticated user ID from the request context.

Types

type UserInfo

type UserInfo struct {
	Login       string `json:"login"`
	DisplayName string `json:"display_name"`
	TailscaleID string `json:"tailscale_id,omitempty"`
	Tailnet     string `json:"tailnet,omitempty"`
}

UserInfo holds identity information for an authenticated user.

func UserInfoFromContext

func UserInfoFromContext(r *http.Request) UserInfo

UserInfoFromContext returns the authenticated user info from the request context.

type UserStore

type UserStore interface {
	GetOrCreateUser(ctx context.Context, login, displayName string) (int, error)
	GetPrimaryUser(ctx context.Context) (int, string, error)
}

UserStore resolves Tailscale identities to application user IDs.

type WhoisClient

type WhoisClient interface {
	WhoIs(ctx context.Context, remoteAddr string) (*apitype.WhoIsResponse, error)
}

WhoisClient looks up the identity of a Tailscale peer.

Jump to

Keyboard shortcuts

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