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 Annotations ¶ added in v0.2.0
func Annotations(src []byte) []model.RouteAnnotation
Annotations returns @route declarations from src. A path-only annotation expands to both GET and POST, matching the HTTP router.
Types ¶
type Module ¶ added in v0.2.1
type Module struct {
platform.UnimplementedModule
// contains filtered or unexported fields
}
Module loads annotated PHP routes into a platform router.
type Option ¶
type Option func(*Service)
Option configures Service.
func WithExcludedDirectory ¶ added in v0.2.0
WithExcludedDirectory skips a top-level directory while scanning routes.
func WithExprCache ¶ added in v0.2.1
WithExprCache sets a shared expression cache to the service.
func WithFlatstack ¶ added in v0.2.1
WithFlatstack enables the flat bytecode runtime with interpreter fallback.
func WithObservers ¶ added in v0.2.1
WithObservers attaches runtime observers to every routed request.
func WithRunnerOptions ¶ added in v0.2.1
WithRunnerOptions configures runtimes created for routed PHP endpoints.
func WithRuntimeFunc ¶
func WithRuntimeFunc(fn RuntimeFunc) Option
WithRuntimeFunc registers fn to customize each request runtime.
type RuntimeFunc ¶
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 ¶
NewService registers annotated PHP endpoints from root on mux.