access

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package access provides access control middleware and utilities for the application.

Package access provides access control middleware and utilities for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(manager *Manager, _ logging.Logger) echo.MiddlewareFunc

Middleware creates a new access control middleware

func TestMatchPathPattern

func TestMatchPathPattern()

TestMatchPathPattern is a simple test function to verify pattern matching

Types

type Config

type Config struct {
	// DefaultAccess is the default access level for routes
	DefaultAccess Level
	// PublicPaths are paths that are always accessible
	PublicPaths []string
	// AdminPaths are paths that require admin access
	AdminPaths []string
}

Config holds the configuration for the access middleware

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type Level

type Level int

Level represents the level of access required for a route

const (
	// Public means no authentication required
	Public Level = iota
	// Authenticated means user must be authenticated
	Authenticated
	// Admin means user must be an admin
	Admin
)

type Manager

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

Manager manages access control rules

func NewManager

func NewManager(config *Config, rules []Rule) *Manager

NewManager creates a new access manager

func (*Manager) AddRule

func (am *Manager) AddRule(rule Rule)

AddRule adds a new access rule

func (*Manager) GetRequiredAccess

func (am *Manager) GetRequiredAccess(path, method string) Level

GetRequiredAccess returns the required access level for a path and method

func (*Manager) IsAdminPath

func (am *Manager) IsAdminPath(path string) bool

IsAdminPath checks if a path requires admin access

func (*Manager) IsPublicPath

func (am *Manager) IsPublicPath(path string) bool

IsPublicPath checks if a path is public

type Rule

type Rule struct {
	Path        string
	AccessLevel Level
	Methods     []string // If empty, applies to all methods
}

Rule defines a rule for route access

func DefaultRules

func DefaultRules() []Rule

DefaultRules returns the default access rules for the application

Jump to

Keyboard shortcuts

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