handler

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JWTAuthMiddleware

func JWTAuthMiddleware(cfg JWTAuthConfig, next http.Handler) http.Handler

JWTAuthMiddleware validates a Bearer token from the Authorization header, extracts the user ID from the configured claim, and sets it in context.

func RetryAfterMiddleware

func RetryAfterMiddleware(check func(r *http.Request) (reject bool, status int, retryAfter int), next http.Handler) http.Handler

RetryAfterMiddleware rejects requests when the check function returns true. The consuming app provides the policy (rate limiting, maintenance mode, etc.).

func UserIDFromContext

func UserIDFromContext(ctx context.Context) string

UserIDFromContext extracts the user ID from the request context. The consuming application is responsible for setting this via WithUserID.

func UserIDMiddleware

func UserIDMiddleware(header string, next http.Handler) http.Handler

UserIDMiddleware is an http.Handler middleware that extracts the user ID from a header and sets it in the request context. The consuming application should replace this with their own auth middleware.

func VersionCheckMiddleware

func VersionCheckMiddleware(header, minVersion string, next http.Handler) http.Handler

VersionCheckMiddleware validates the client version header against the minimum.

func WithUserID

func WithUserID(ctx context.Context, userID string) context.Context

WithUserID returns a new context with the user ID set. UUIDs are normalized to lowercase per RFC 4122 / PostgreSQL convention.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler provides net/http handlers for sync endpoints.

func New

func New(engine *synchro.Engine, opts ...Option) *Handler

New creates a new sync HTTP handler.

func (*Handler) Routes

func (h *Handler) Routes() http.Handler

Routes returns an http.Handler with all sync endpoints mounted.

func (*Handler) ServePull

func (h *Handler) ServePull(w http.ResponseWriter, r *http.Request)

ServePull handles POST /sync/pull.

func (*Handler) ServePush

func (h *Handler) ServePush(w http.ResponseWriter, r *http.Request)

ServePush handles POST /sync/push.

func (*Handler) ServeRegister

func (h *Handler) ServeRegister(w http.ResponseWriter, r *http.Request)

ServeRegister handles POST /sync/register.

func (*Handler) ServeSchema

func (h *Handler) ServeSchema(w http.ResponseWriter, r *http.Request)

ServeSchema handles GET /sync/schema.

func (*Handler) ServeSnapshot

func (h *Handler) ServeSnapshot(w http.ResponseWriter, r *http.Request)

ServeSnapshot handles POST /sync/snapshot.

func (*Handler) ServeTableMeta

func (h *Handler) ServeTableMeta(w http.ResponseWriter, r *http.Request)

ServeTableMeta handles GET /sync/tables.

type JWTAuthConfig

type JWTAuthConfig struct {
	// Secret is the HS256 shared secret. Mutually exclusive with JWKSURL.
	Secret []byte
	// JWKSURL is the RS256/ES256 JWKS endpoint URL. Mutually exclusive with Secret.
	JWKSURL string
	// UserClaim is the JWT claim containing the user ID (default: "sub").
	UserClaim string
}

JWTAuthConfig configures JWT-based authentication middleware.

type Option

type Option func(*Handler)

Option configures a Handler.

func WithDefaultRetryAfter

func WithDefaultRetryAfter(seconds int) Option

WithDefaultRetryAfter sets the default Retry-After seconds for transient errors.

Jump to

Keyboard shortcuts

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