docs(pact,party,surf): compile README Go examples via src= (quick-261118-qsd)

This commit is contained in:
Jakub Zych
2026-11-18 20:07:39 +01:00
parent cd55a3980d
commit a2551d83d7
6 changed files with 257 additions and 86 deletions

View File

@@ -46,25 +46,11 @@ Use cases:
## Usage
A plugin declares its capabilities by implementing the interfaces and asserting them at compile time:
A plugin declares its capabilities by implementing the interfaces, and asserts them at compile time with lines such as `var _ pact.HasRoutes = (*BlogPlugin)(nil)`:
```go
package blog
import (
"net/http"
"git.golem15.com/golem15/summercms/modules/pact"
)
var (
_ pact.HasRoutes = (*Plugin)(nil)
_ pact.HasPermissions = (*Plugin)(nil)
)
type Plugin struct{}
func (p *Plugin) Routes(r pact.Router) error {
```go src=modules/pact/example_test.go#BlogPlugin.Routes
// Routes declares the plugin's JSON API behind the auth middleware.
func (p *BlogPlugin) Routes(r pact.Router) error {
r.Group("/api/blog", []string{"auth"}, func(r pact.Router) {
r.Get("/posts", listPosts)
r.Get("/posts/{id}", showPost)
@@ -72,26 +58,26 @@ func (p *Plugin) Routes(r pact.Router) error {
})
return nil
}
```
func (p *Plugin) Permissions() []pact.Permission {
```go src=modules/pact/example_test.go#BlogPlugin.Permissions
// Permissions declares the backend permission that guards the post screens.
func (p *BlogPlugin) Permissions() []pact.Permission {
return []pact.Permission{
{Code: "acme.blog.access_posts", Tab: "Blog", Label: "Manage posts"},
}
}
func listPosts(w http.ResponseWriter, r *http.Request) {}
func showPost(w http.ResponseWriter, r *http.Request) {}
```
A plugin schedules one of its registered commands by implementing `pact.HasSchedule`:
A plugin schedules its registered console commands by implementing `pact.HasSchedule`:
```go
var _ pact.HasSchedule = (*Plugin)(nil)
func (p *Plugin) Schedule() []pact.ScheduledCommand {
```go src=modules/pact/example_test.go#BlogPlugin.Schedule
// Schedule runs three of the plugin's registered console commands.
func (p *BlogPlugin) Schedule() []pact.ScheduledCommand {
return []pact.ScheduledCommand{
{Command: "blog:prune-drafts", Cadence: pact.Daily()},
{Command: "blog:ping", Args: []string{"--quiet"}, Cadence: pact.Every(15 * time.Minute)},
{Command: "blog:send-digest", Cadence: pact.DailyAt(7, 30)},
{Command: "blog:sync-feed", Args: []string{"--quiet"}, Cadence: pact.Every(15 * time.Minute)},
}
}
```