Documentation
¶
Overview ¶
Package externalscan reads the Go signatures of the package-level functions a template may call as externals, and reports the two things generation cannot learn from the template: which take a leading context.Context, and which return a trailing error.
Both are properties of the implementation rather than the declaration, so a template says the same thing either way and the choice belongs to whoever writes the function.
Both paths that compile a template use this: the generator, for a templates package, and routetree, for a route package. They share it so one definition decides what a signature means, and so a declaration means the same thing wherever it is written.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Signatures ¶
type Signatures struct {
// Context names the functions declaring a leading context.Context.
//
// An async external gets the boundary's context, which is what lets a call
// that can abort observe cancellation. A synchronous one gets the render
// context at the position it occupies, which is what lets a value belonging
// to the request — a CSRF token, a nonce — render inline without travelling
// through the parameter struct of every page that needs it.
Context map[string]bool
// Error names the functions whose last result is an error.
//
// A synchronous external is otherwise total: it answers or it does not
// return. Declaring an error gives a call that can fail somewhere to say so,
// and the template has to give that failure a place to go, which is why the
// compiler restricts where such a function may be called.
Error map[string]bool
}
Signatures reports what a scan found. A name is present in a map only when the corresponding property holds, so an absent name simply means the plain shape.
func Scan ¶
func Scan(dir string) (Signatures, error)
Scan reads every Go file in dir and reports the signatures generation needs.
Detection is syntactic on purpose. It runs before the package compiles, so a file that does not parse is skipped rather than failing generation; a call shape that then does not match is an ordinary Go compile error at the generated call site.