guard

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNativeRBACGuard

func IsNativeRBACGuard(name string) bool

IsNativeRBACGuard reports whether name is a built-in role or permission guard.

func Redirect added in v0.5.0

func Redirect(url string, status int) error

Redirect returns an error that generated guard handling translates into a no-store local redirect with the provided 3xx status.

func RedirectTo added in v0.5.0

func RedirectTo(url string) error

RedirectTo returns an error that generated guard handling translates into a no-store local redirect.

func Respond added in v0.5.0

func Respond(result response.Response) error

Respond returns an error that generated guard handling translates into a no-store runtime response.

func ResponseResult added in v0.5.0

func ResponseResult(err error) (response.Response, bool)

ResponseResult extracts a generated guard response error.

func RunGuards

func RunGuards(ctx Context, names []string, registry Registry) error

RunGuards executes guard IDs in declaration order.

func RunGuardsWithAuth

func RunGuardsWithAuth(ctx Context, names []string, registry Registry, provider auth.Provider) error

RunGuardsWithAuth executes guard IDs in declaration order and resolves native RBAC guard IDs such as role:admin and permission:posts.write through provider.

func WriteNoStoreFailure added in v0.5.0

func WriteNoStoreFailure(writer http.ResponseWriter, err error)

WriteNoStoreFailure writes a generated guard failure response. Ordinary guard errors fail closed with 403; guard response helpers keep the same no-store cache policy while allowing explicit redirects or response shapes.

func WriteNoStoreLocalizedFailure added in v0.13.0

func WriteNoStoreLocalizedFailure(writer http.ResponseWriter, err error, bundle i18n.ErrorBundle, locale string)

WriteNoStoreLocalizedFailure localizes ordinary guard denials. Explicit redirect/response errors retain their application-owned response.

Types

type Context

type Context struct {
	Context context.Context
	Request *http.Request
	Session map[string]any
}

Context is passed to generated request-time guard functions.

func NewContext

func NewContext(request *http.Request, session map[string]any) Context

NewContext creates the first-slice request context for generated guards.

type Func

type Func func(Context) error

Func authorizes one generated request-time route or endpoint access check.

func NativeRBACGuard

func NativeRBACGuard(name string, provider auth.Provider) Func

NativeRBACGuard returns a guard for a native role or permission guard ID.

type RedirectError added in v0.5.0

type RedirectError struct {
	URL    string
	Status int
}

RedirectError asks generated guard handling to issue a safe local redirect.

func (RedirectError) Error added in v0.5.0

func (err RedirectError) Error() string

type Registry

type Registry map[string]Func

Registry resolves guard IDs to executable guard functions.

type ResponseError added in v0.5.0

type ResponseError struct {
	Result response.Response
}

ResponseError asks generated guard handling to write a runtime response.

func (ResponseError) Error added in v0.5.0

func (err ResponseError) Error() string

Jump to

Keyboard shortcuts

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