route

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package route scans a PHP source tree of .php files and registers Go standard library routes for annotated PHP endpoints on a standard library mux router.

Each PHP endpoint gives a hint using a comment with an annotation tag:

  • `// @route GET /users/{id}`
  • `// @route POST /users/{id}`
  • `// @route <method> <path>`

An annotation tag can be repeated to register multiple handlers. In the case of a duplicate handler being registered, the last one wins and a warning is printed in the logs. The annotation tag can be followed by an optional colon. One route per line.

If method is omitted, only GET and POST are routed to the handler. This ignores requests like HEAD and OPTIONS, ideally leaving these to be resolved in the router, rather than invoking PHP.

Specific HTTP methods like PUT are only reachable when explicitly stated.

The .php files are scanned recursively, so you may keep them in a single folder, or just place them in arbitrary subfolders. Files without annotations will be skipped.

This functionality fills a phpscript-specific auto-global value:

  • `$_PATH`, specifically `$_PATH['id']`.

It relies on the Go standard library to extract path parameters present.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithContextValue

func WithContextValue(key, value any, next http.Handler) http.Handler

WithContextValue returns middleware that stores key/value on request context.

Types

type Option

type Option func(*Service)

Option configures Service.

func WithRuntimeFunc

func WithRuntimeFunc(fn RuntimeFunc) Option

WithRuntimeFunc registers fn to customize each request runtime.

type RuntimeFunc

type RuntimeFunc func(*runner.Runtime)

RuntimeFunc customizes a PHP runtime before a routed PHP endpoint executes.

type Service

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

Service owns route registration for annotated PHP endpoints.

func NewService

func NewService(root fs.FS, mux *http.ServeMux, opts ...Option) (*Service, error)

NewService registers annotated PHP endpoints from root on mux.

func (*Service) Register

func (m *Service) Register(root fs.FS) error

Register walks root for .php files and registers their @route annotations.

Jump to

Keyboard shortcuts

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