router

package
v0.1.171 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	contract.RouterOperator
}

func NewClient

func NewClient(d Dependencies, opts ClientOptions) (Client, error)

type ClientOption

type ClientOption func(*ClientOptions)

func WithDashboard added in v0.1.11

func WithDashboard() ClientOption

func WithPathKey

func WithPathKey(x string) ClientOption

func WithRessourceKey

func WithRessourceKey(x string) ClientOption

type ClientOptions

type ClientOptions struct {
	Dashboard    bool
	PathKey      string
	RessourceKey string
}

func ApplyClientOptions

func ApplyClientOptions(opts *ClientOptions, modifiers ...ClientOption) ClientOptions

type DefaultTool added in v0.1.11

type DefaultTool struct {
	T *contract.Tool[Client]
}

func NewTool

func NewTool(c Client, opts contract.ToolOptions[Client]) *DefaultTool

func (*DefaultTool) AttachServer added in v0.1.26

func (d *DefaultTool) AttachServer(ctx context.Context, s contract.ServerOperator)

AttachServer attaches the server operator to the router.

func (*DefaultTool) Mount added in v0.1.11

func (d *DefaultTool) Mount(ctx context.Context, r []*contract.Route) error

Mount mounts the routes to the router.

func (*DefaultTool) PKey added in v0.1.11

func (d *DefaultTool) PKey(ctx context.Context) string

PKey returns the path key configured for the router.

func (*DefaultTool) ParsePath added in v0.1.27

func (d *DefaultTool) ParsePath(ctx context.Context, r *http.Request, re *regexp.Regexp) map[string]string

ParsePath extracts path parameters using the route regex.

func (*DefaultTool) ParseQuery added in v0.1.27

func (d *DefaultTool) ParseQuery(ctx context.Context, r *http.Request) map[string][]string

ParseQuery returns query parameters from the request.

func (*DefaultTool) Run added in v0.1.11

func (d *DefaultTool) Run(ctx context.Context) error

Run starts the router server.

func (*DefaultTool) Stop added in v0.1.11

func (d *DefaultTool) Stop(ctx context.Context) error

Stop gracefully shuts down the router server.

func (*DefaultTool) Vars added in v0.1.11

func (d *DefaultTool) Vars(ctx context.Context) (*config.Vars, error)

Vars extracts routing variables from context.

type Pattern

type Pattern = string

Pattern represents a regex pattern string.

const (
	// PatID matches numeric path parameters (e.g., user ID).
	PatID Pattern = `[0-9]+`
	// PatName matches alphabetic characters only (uppercase or lowercase).
	PatName Pattern = `[a-zA-Z]+`
	// PatWord matches any word-like token (alphanumeric and underscore).
	PatWord Pattern = `\w+`
	// PatWordCI matches word-like tokens, case-insensitive.
	PatWordCI Pattern = `(?i)\w+`
	// PatEmail matches a basic email address format.
	PatEmail Pattern = `[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`
	// PatOID matches a 24-character hexadecimal string (MongoDB ObjectID).
	PatOID Pattern = `[0-9a-fA-F]{24}`
	// PatFile matches any file name with an extension.
	PatFile Pattern = `.*\.[^/]*$`
	// PatUUID matches a UUID string in standard 8-4-4-4-12 format.
	PatUUID Pattern = `[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`
)

Jump to

Keyboard shortcuts

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