routing

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CatchAllSegment = "**"

CatchAllSegment is the pattern's final-segment marker that turns a route into a file-server style catch-all — it matches one or more real URL segments after the literal prefix.

Variables

View Source
var GlobalRouteBuilder = &RouteBuilder{}

Functions

func LiteralPrefixLen added in v0.1.9

func LiteralPrefixLen(pattern string) int

LiteralPrefixLen counts the leading pattern segments that are pure literals (not `{placeholder}`, not `**`). Used as the tie-breaker when multiple patterns match the same URL — the route with the longest literal prefix wins, so `/public/media/files/{id}` beats `/public/media/**` for the URL `/public/media/files/abc`.

func MatchPath added in v0.1.8

func MatchPath(pattern, path string) bool

MatchPath returns true when `pattern` matches the real URL `path`.

Rules:

  • Literal segments must equal their counterpart.
  • `{placeholder}` matches any single real segment (both plain values and the IAM `{id:<value>}` wrapped convention).
  • `**` is only valid as the pattern's final segment and greedily matches one or more real segments. The consumed remainder is recovered via PathRemainder(pattern, path).

func PathRemainder added in v0.1.9

func PathRemainder(pattern, path string) string

PathRemainder returns the tail of `path` that the `**` segment absorbed when the given pattern matched. For non-catch-all patterns (or mismatches) it returns "".

Types

type HandlerInterface

type HandlerInterface interface {
	ServeHTTP(ctx request.RequestContext)
}

type Route

type Route struct {
	Path        string
	Method      string
	Executor    string
	ContentType string
}

type RouteBuilder

type RouteBuilder struct {
	HandlerMap    map[string]HandlerInterface
	Context       serverdi.Context
	SecurityLayer security.SecurityLayer
	// contains filtered or unexported fields
}

func (*RouteBuilder) AddContext

func (rb *RouteBuilder) AddContext(ctx serverdi.Context)

func (*RouteBuilder) AddRoute

func (rb *RouteBuilder) AddRoute(route Routes)

func (*RouteBuilder) Build

func (rb *RouteBuilder) Build(log logger.Logger) http.Handler

func (*RouteBuilder) ServeHTTP

func (rb *RouteBuilder) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*RouteBuilder) SetSecurityLayer added in v0.1.4

func (rb *RouteBuilder) SetSecurityLayer(layer security.SecurityLayer)

type RouteConfig

type RouteConfig struct {
	Path        string        `yaml:"path"`
	Method      string        `yaml:"method"`
	Executor    string        `yaml:"executor"`
	ContentType string        `yaml:"content_type"`
	Security    string        `yaml:"security"`
	Scopes      []string      `yaml:"scopes"`
	Children    []RouteConfig `yaml:"children"`
}

type RouteHandler

type RouteHandler struct {
	Method   string
	Pattern  string
	Security string
	Scopes   []string
	Handler  http.HandlerFunc
}

type Routes

type Routes struct {
	YamlContent []byte
	HandlerMap  map[string]HandlerInterface
}

type RoutesYAML

type RoutesYAML struct {
	APIPrefix string        `yaml:"api_prefix"`
	Routes    []RouteConfig `yaml:"routes"`
}

type RoutingBuilder

type RoutingBuilder struct {
	Context       serverdi.Context
	SecurityLayer security.SecurityLayer
	// contains filtered or unexported fields
}

func NewRoutingBuilder

func NewRoutingBuilder() *RoutingBuilder

func RegisterRoutes

func RegisterRoutes(routeConfigs Routes, log logger.Logger, ctx serverdi.Context) *RoutingBuilder

func (*RoutingBuilder) AddContext

func (rb *RoutingBuilder) AddContext(ctx serverdi.Context)

func (*RoutingBuilder) AddRoute

func (rb *RoutingBuilder) AddRoute(method, pattern, securityType string, scopes []string, handler http.HandlerFunc)

func (*RoutingBuilder) Build

func (rb *RoutingBuilder) Build() http.Handler

func (*RoutingBuilder) ServeHTTP

func (rb *RoutingBuilder) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*RoutingBuilder) SetSecurityLayer added in v0.1.4

func (rb *RoutingBuilder) SetSecurityLayer(layer security.SecurityLayer)

Jump to

Keyboard shortcuts

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