server

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Body(
	c *echo.Context,
	in any,
) (string, bool)

Body decodes the JSON body into in. An empty body leaves in as it is, for Valid to report what is missing.

func Deps

func Deps[D any](
	s *Server,
) D

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

func Form(
	c *echo.Context,
	in any,
) (string, bool)

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 Param

func Param[T any](
	c *echo.Context,
	name string,
	field *T,
) (string, bool)

Param sets *field from the path parameter name, the method's key.

func Path

func Path(
	g *endpoint.Group,
	m *endpoint.Method,
) string

Path is the echo path of a method: its route, with {param} written as :param.

func Query

func Query[T any](
	c *echo.Context,
	name string,
	field *T,
) (string, bool)

Query sets *field from the query parameter name, when the request has it.

func Register

func Register(
	routes func(s *Server) []Route,
)

Register adds one group's generated routes. Each gen/api.go calls it from init.

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.

func Valid

func Valid(
	c *echo.Context,
	in any,
) (string, bool)

Valid checks in's validate tags, and each string field tagged pattern:"..." against its regular expression, with the request's context, so a rule that reads NATS, such as valid_target, is in its trace.

Types

type Decoder

type Decoder[In any] func(c *echo.Context) (In, string, bool)

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.

func New

func New(
	logger *slog.Logger,
	signingKeys authtoken.Keys,
	customRoles authtoken.CustomRoles,
	deps ...any,
) *Server

New returns the server the generated routes run on. deps are the values each group Uses, one of each type.

func (*Server) Mount

func (s *Server) Mount(
	e *echo.Echo,
	routes []Route,
)

Mount adds routes to e, each behind the check that the request's token grants its permission. A route with no permission is public.

type Vaults

type Vaults interface {
	Get(name string) (vault.Vault, bool)
	Spec(name string) (vault.Spec, bool)
}

Vaults are the vaults that a reference names, by name: the vaults of controller.secrets.vaults. The controller gives its *vault.Set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL