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 ¶
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 ¶
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.