Documentation
¶
Overview ¶
Package server is the runtime the generated routes of an endpoint group call. Each group's gen/api.go lists its routes and registers them here; each gen/api_<method>.go decodes the method's typed input and hands it to Serve, which runs the method's handler and maps its error to a status.
Index ¶
- Constants
- func Body(c *echo.Context, in any) (string, bool)
- func Deps[D any](s *Server) D
- func Form(c *echo.Context, in any) (string, bool)
- func Handler(logger *slog.Logger, signingKeys authtoken.Keys, ...) []func(e *echo.Echo)
- func Param[T any](c *echo.Context, name string, field *T) (string, bool)
- func Path(g *endpoint.Group, m *endpoint.Method) string
- func Query[T any](c *echo.Context, name string, field *T) (string, bool)
- func Register(routes func(s *Server) []Route)
- func Serve[D, In, Out any](s *Server, g *endpoint.Group, method string, ...) echo.HandlerFunc
- func Valid(c *echo.Context, in any) (string, bool)
- type Decoder
- type Route
- type Secrets
- type Server
- type Vaults
Constants ¶
const PermSecretUse authtoken.Permission = "secret:use"
PermSecretUse is the permission that a request needs for each reference, secret://<vault>/<key>, that it gives: to use a secret is to read it.
Variables ¶
This section is empty.
Functions ¶
func Body ¶
Body decodes the JSON body into in. An empty body leaves in as it is, for Valid to report what is missing.
func Deps ¶
Deps is the value of type D that the server was given. A group whose dependencies the controller did not give is a mistake in the wiring, so it panics at startup, when the routes are made. An empty struct needs no wiring: a new group starts with one, and its first field makes the controller give it.
func Form ¶
Form reads the fields of in that are tagged in:"form" from a multipart/form-data body: a string from its value, and a []byte from the file of that name.
func Handler ¶
func Handler( logger *slog.Logger, signingKeys authtoken.Keys, customRoles authtoken.CustomRoles, deps ...any, ) []func(e *echo.Echo)
Handler returns the route registrations for every registered group.
func Serve ¶
func Serve[D, In, Out any]( s *Server, g *endpoint.Group, method string, run func(context.Context, D, In) (Out, error), decode Decoder[In], ) echo.HandlerFunc
Serve is the handler of one method: it decodes the input, runs the method's handler with the group's dependencies, and writes the output with the method's success status, or the error with the status that Errors maps it to, or 500.
Types ¶
type Decoder ¶
Decoder reads a method's typed input from the request, and says what is wrong when it cannot.
type Route ¶
type Route struct {
Method string
Path string
Permission string
Handler echo.HandlerFunc
}
Route is one generated endpoint: its HTTP method, its echo path, the permission a token needs ("" for a public one), and the handler.
type Secrets ¶
type Secrets struct {
Vaults Vaults
}
Secrets is what the server resolves each reference with. The controller gives it to New with the deps of the groups. A server with no Secrets has no vault, so it refuses each reference.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is what every generated route shares: what it takes to check a token, and the dependencies of each group, by type.