mirror of
https://github.com/zap-proto/zip.git
synced 2026-10-19 15:38:57 +00:00
A host that re-exports the type writes `type Router = *zip.App` and hands a Router to every plugin. That is the same type, but it arrives as types.Alias, so matching the shape directly saw neither an App nor a Group and the op's prefix could not be resolved — which refuses the whole document rather than filing one path wrongly. Unalias at each place a type is matched by shape, including the In and Out inferred from a handler. A group is also read when var names it, not only :=. The prefix belongs to the Group call; the syntax that binds the result does not change it. Co-authored-by: Hanzo Dev <[email protected]>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Package alias registers ops on a router named by an alias, which is how a
|
|
// host that re-exports the type spells it: the host's own package says
|
|
// `type Router = *zip.App`, and every plugin mount takes a Router.
|
|
package alias
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zap-proto/zip"
|
|
)
|
|
|
|
//go:generate zipdoc
|
|
|
|
// Router is this host's name for the app a plugin mounts on.
|
|
type Router = *zip.App
|
|
|
|
// Branch is this host's name for a confined part of it.
|
|
type Branch = *zip.Group
|
|
|
|
// AskIn is the question.
|
|
type AskIn struct {
|
|
// Prompt is what to answer.
|
|
Prompt string `json:"prompt"`
|
|
}
|
|
|
|
// AskOut is the answer.
|
|
type AskOut struct {
|
|
// Reply is the answer.
|
|
Reply string `json:"reply"`
|
|
}
|
|
|
|
// Ask answers a question.
|
|
func Ask(ctx context.Context, in *AskIn) (*AskOut, error) { return &AskOut{Reply: in.Prompt}, nil }
|
|
|
|
// Mount declares one op on an aliased router and one on an aliased group.
|
|
func Mount(r Router) {
|
|
r.Post("/v1/ask", Ask)
|
|
|
|
var b Branch = r.Group("/v1/ask/history")
|
|
b.Post("/replay", Ask)
|
|
|
|
var plain = r.Group("/v1/ask/audit")
|
|
plain.Post("/entries", Ask)
|
|
}
|