Documentation
¶
Overview ¶
Package rpcgen reads the rpc/ package of an app and writes the Go code of calls between apps: the codec and method table of the app that serves the functions, and the clients of the apps that call them.
Index ¶
- func AddedPackageName(app string, held []string) (string, error)
- func Calls(dir, module string, held map[string]rpcschema.Schema) (map[string][]string, error)
- func Client(app string, s rpcschema.Schema) ([]byte, error)
- func Codec(s rpcschema.Schema, declare bool) []byte
- func PackageName(app string) (string, error)
- func PackageNames(apps []string) (map[string]string, error)
- func Server(p Package, s rpcschema.Schema) ([]byte, error)
- type Access
- type Func
- type Package
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddedPackageName ¶
AddedPackageName returns the client package name of app for a calling app that holds the snapshots of the apps in held, before it holds that of app. It refuses, with E-RPC-006, what PackageNames refuses in held, and, with no position, what PackageName refuses and a package name that the client of another app in held has.
func Calls ¶
Calls returns, by app, the functions of the apps in held that the Go code of the app in dir refers to, sorted. held maps every app whose snapshot the app holds to that snapshot; the app's client is the package <module>/services/<package name>. Calls reads every regular Go file of the app that is neither a test nor generated, outside services/, other modules and the folders Go skips, and collects each selector <name>.<Func> where <name> is the client's name in that file and <Func> a function of its app. Dot imports are not followed. An app with no such selector has no entry.
The scan is syntactic: in a file that imports a client, a selector on any other value with the client's name, such as a local variable that shadows it, counts too. That can only widen what the app declares it calls; the called app and the runner still check every call. A file with syntax errors is read as far as it parses; the Go build reports the errors.
func Client ¶
Client returns services/<package>/client_gen.go for app, whose snapshot, as rpcschema.Parse read it, a calling app holds as s: the types of s with their codec, and for every function of app a function of the same name that calls it through the runner. It refuses, with E-RPC-005, a type name that is not exported, and what PackageName refuses.
func Codec ¶
Codec returns Go source, without a package clause or imports, that gives every type of s two methods for the proto3 wire format with the field numbers of s:
- aicodedAppend(b []byte) []byte appends the fields of the value to b. A singular field is left out when it holds its zero value, a non-nil pointer is always written, and a repeated field writes every element.
- aicodedDecode(n protowire.Number, v wire.Value) error reads field n into the value, for wire.Decode and wire.Value.Decode. Unknown fields are skipped, repeated scalars are taken packed or not, and a nested struct starts from its zero value each time it arrives.
With declare, the source also declares the types. It uses the packages protowire and wire, and time when it declares a type with a time field.
func PackageName ¶
PackageName returns the name of the client package of app: the app's name without its dashes. It refuses, with E-RPC-006 and no position, a name that is not an app name, and one whose package name Go reserves: a keyword, a predeclared identifier, main or init.
func PackageNames ¶
PackageNames returns the client package name of every app in apps, whose snapshots a calling app holds, by app. It refuses, with E-RPC-006 at the held snapshot, what PackageName refuses and two apps whose clients would have the same name.
func Server ¶
Server returns rpc/server_gen.go of the package p, whose types s numbers: the codec of the types, and the function Server, which serves every function of p with the callers, role rule and apps flag of its //ssr:access line. A served function decodes its input, runs, and encodes its output.
Types ¶
type Access ¶
Access says who may call a function: the calling apps, the role rule a viewer must meet, written as in the access section and empty without role=, and whether an app may call the function with no viewer.
type Func ¶
Func is an exported function of the rpc/ package: its name, the names of its input and output types, who may call it, and its position as file:line relative to the app.
type Package ¶
Package is the rpc/ package of the app in Dir: its functions sorted by name, and the schema of the types they take and return. The schema is unnumbered, names no app, and holds only the types the functions reach.