featuregate

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package featuregate provides go-router middleware for wiring go-featuregate scope and actor data into request contexts. This package is the only place in go-router that should import go-featuregate so the core router stays dependency-free.

Usage:

mw := featuregate.New(
	featuregate.WithClaimsResolver(func(ctx router.Context) (gate.ActorClaims, error) {
		return gate.ActorClaims{
			TenantID:  ctx.Param("tenant_id"),
			OrgID:     ctx.Param("org_id"),
			SubjectID: ctx.Locals("user_id").(string),
		}, nil
	}),
)

app.Use(mw)

app.Get("/users", func(ctx router.Context) error {
	enabled, err := gate.Enabled(ctx.Context(), "users.read")
	if err != nil {
		return err
	}
	if !enabled {
		return router.NewNotFoundError("not found")
	}
	return ctx.JSON(200, map[string]string{"ok": "true"})
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActorFromContext

func ActorFromContext(ctx context.Context) (gate.ActorRef, bool)

ActorFromContext returns the actor reference stored by the middleware.

func Context

func Context(ctx router.Context) context.Context

Context returns the standard context from a router.Context.

func New

func New(opts ...Option) router.MiddlewareFunc

Types

type ActorResolver

type ActorResolver func(router.Context) gate.ActorRef

type ClaimsResolver

type ClaimsResolver func(router.Context) (gate.ActorClaims, error)

type Option

type Option func(*config)

func WithActorResolver

func WithActorResolver(resolver ActorResolver) Option

func WithClaimsResolver

func WithClaimsResolver(resolver ClaimsResolver) Option

func WithStrict

func WithStrict(strict bool) Option

Jump to

Keyboard shortcuts

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