Documentation
¶
Overview ¶
Package generate turns an app's pages/ folder into Go code, assets and live-page scripts.
Index ¶
- func CheckHeld(app string, apps map[string]string) ([]string, error)
- func CheckSnapshots(apps map[string]string) ([]string, error)
- func Generate(dir string) error
- func HeldApps(dir string) ([]string, error)
- func WriteFile(dir, name string, data []byte) error
- type App
- type Diagnostics
- type FieldInfo
- type FormInfo
- type Options
- type ParamInfo
- type Result
- type Route
- type RouteInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckHeld ¶
CheckHeld checks the snapshots that the app named app holds, as CheckSnapshots does for every app of apps.
func CheckSnapshots ¶
CheckSnapshots checks every snapshot of a called app that an app of the workspace holds, .aicoded/services/<app>.json, against the called app's current .aicoded/rpc.json. apps maps each app's name to its folder. It fails with E-RPC-013 at the first held snapshot the called app breaks, and returns one warning for each held app that is not in apps.
func Generate ¶
Generate turns the app in dir into generated code: its pages/ folder into Go code and assets, its rpc/ package into the method table and codec the app serves other apps with, pinning the field numbers in .aicoded/rpc.json, and the snapshots in .aicoded/services/ into the clients of the apps it calls. It writes the access and services sections of the app's permission list, aicoded.yaml, when the app has one. It writes nothing unless every step succeeds and the permission list can take the sections. It is Run with the apps next to dir as the workspace.
Types ¶
type Diagnostics ¶
Diagnostics is every coded problem one run found, so all broken templates are reported at once.
func (Diagnostics) Err ¶
func (d Diagnostics) Err() error
Err returns d sorted by position, or nil when it is empty.
func (Diagnostics) Error ¶
func (d Diagnostics) Error() string
func (Diagnostics) Unwrap ¶
func (d Diagnostics) Unwrap() []error
Unwrap returns the diagnostics as errors, so errors.As and errs.Code find the first one.
type FieldInfo ¶
type FieldInfo struct {
Name string `json:"name"`
Kind string `json:"kind"`
GoType string `json:"go_type"`
Required bool `json:"required"`
Multiple bool `json:"multiple"`
}
FieldInfo is a form field: Kind is "input", "file", "textarea" or "select", and GoType the Go type its value is read into. Radio and checkbox inputs that share a name are one field.
type Options ¶
type Options struct {
// Workspace maps the name of every app of the workspace to its folder. With nil, the
// workspace is the apps in the folders directly next to dir, and two of them with one name
// that hold a snapshot of this app are E-DEV-010.
Workspace map[string]string
// Frozen writes nothing; every generated file that would change is an E-CHK-001 problem.
Frozen bool
// Module is the import path of dir, for an app that lies inside an enclosing module and has
// no go.mod of its own. With "", the go.mod in dir names it.
Module string
}
Options says how Run generates an app.
type ParamInfo ¶
ParamInfo is a parameter of a URL: Kind is "number" for an n_ folder and "string" for an s_ folder.
type Result ¶
type Result struct {
// Changed lists the generated files written, or with Frozen the ones that differ,
// relative to the app folder, slash-separated and sorted. Removed files are included.
Changed []string
// Files lists every file the generator owns in the app: the generated Go and TypeScript
// files, the built assets and the snapshot of the functions the app serves, relative to the
// app folder, slash-separated and sorted. Every other file of the app is hand-written.
Files []string
// Warnings are the esbuild warnings, each "<file>:<line>: <text>".
Warnings []string
// Routes lists every page and layout of the app, sorted by URL pattern.
Routes []RouteInfo
}
Result is what Run changed and what it warns about.
type Route ¶
type Route struct {
Path string
Dir string
Template *template.Template
// contains filtered or unexported fields
}
Route is a folder under pages/ with an index.html. Path is its URL pattern, such as /notes/n_id, and Dir its absolute folder.
type RouteInfo ¶
type RouteInfo struct {
// Path is the URL pattern, as the access section writes it, such as /trips/{id}.
Path string `json:"path"`
// Template is the route's template, relative to the app folder.
Template string `json:"template"`
// Layout tells a layout with pages below it, which only redirects to one of them and has no
// entry in the access section.
Layout bool `json:"layout"`
// Params are the parameters of the URL, in path order.
Params []ParamInfo `json:"params"`
// Require holds the role rules a viewer must meet, as the access section writes them.
Require []string `json:"require"`
// Guard tells whether a Guard runs on the path, and GuardAt is the path of the route whose
// template declares the nearest one, or "".
Guard bool `json:"guard"`
GuardAt string `json:"guard_at"`
// says.
Shared bool `json:"shared"`
// Live tells whether the route or a layout above it has live values or page calls, so that
// its page opens a live connection at <path>/__ws.
Live bool `json:"live"`
// Calls names the page calls of the routes that render the page.
Calls []string `json:"calls"`
// Forms are the forms of the route's own template, in template order.
Forms []FormInfo `json:"forms"`
}
RouteInfo is one page or layout of an app, as its templates and the access section describe it. The delivery pipeline's simulated attacks are built from it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gobuf builds Go source for generated page code.
|
Package gobuf builds Go source for generated page code. |
|
Package template parses page templates (index.html) into nodes that write Go code.
|
Package template parses page templates (index.html) into nodes that write Go code. |
|
htmlutils
Package htmlutils holds element sets of the HTML syntax.
|
Package htmlutils holds element sets of the HTML syntax. |