Documentation
¶
Overview ¶
Package api is a platform module: a gRPC server and a REST gateway in front of it, with the interceptors every service needs and the OpenAPI description of the API.
The project writes proto files and handlers and registers its services from wireDomain; the module owns the servers, the interceptor chain, the gateway options, health, metrics, CORS and the documentation page.
Index ¶
- func AddStreamInterceptor(app *platform.App, i grpc.StreamServerInterceptor)
- func AddUnaryInterceptor(app *platform.App, i grpc.UnaryServerInterceptor)
- func HandleHTTP(app *platform.App, pattern string, h http.Handler)
- func Register(app *platform.App, s Service)
- func UseHTTP(app *platform.App, mw func(http.Handler) http.Handler)
- type Config
- type Module
- func (m *Module) GRPCAddr() string
- func (m *Module) HTTPAddr() string
- func (m *Module) Health(context.Context) error
- func (m *Module) Init(_ context.Context, app *platform.App) error
- func (m *Module) Name() string
- func (m *Module) Start(ctx context.Context) error
- func (m *Module) Stop(ctx context.Context) error
- type Option
- type Registry
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddStreamInterceptor ¶
func AddStreamInterceptor(app *platform.App, i grpc.StreamServerInterceptor)
AddStreamInterceptor adds a project stream interceptor.
func AddUnaryInterceptor ¶
func AddUnaryInterceptor(app *platform.App, i grpc.UnaryServerInterceptor)
AddUnaryInterceptor adds a project interceptor, such as authentication. Project interceptors run after recovery, metrics and logging and before request validation.
func HandleHTTP ¶
HandleHTTP serves a plain HTTP route next to the gateway: webhooks, file downloads, anything that is not a gRPC call.
Types ¶
type Config ¶
type Config struct {
GRPCAddr string // gRPC listen address
HTTPAddr string // REST gateway listen address
MaxRecvSize int // largest request message, bytes
MaxSendSize int // largest response message, bytes
CORSOrigins []string // origins allowed to call the REST API from a browser; "*" allows any
Docs bool // serve /openapi.yaml and the /docs page
Reflection bool // gRPC server reflection, for grpcurl and similar tools
}
Config holds module settings. Load fills it from the environment; the platform generator writes the Load call into the project's config.gen.go.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements platform.Module.
func (*Module) Init ¶
Init puts the registry into the container, so wireDomain can register services.
type Option ¶
type Option func(*Module)
Option configures the module.
func WithOpenAPI ¶
WithOpenAPI gives the module the generated OpenAPI description: a directory holding openapi.yaml. The generated wiring passes the embedded api/openapi directory.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds what the project adds to the API. It lives in the container and is filled from wireDomain, before the module starts.
type Service ¶
type Service struct {
GRPC func(*grpc.Server)
Gateway func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
}
Service is a gRPC service of the project and, optionally, its REST gateway. Both functions are generated: RegisterXServer from protoc-gen-go-grpc and RegisterXHandler from protoc-gen-grpc-gateway.
api.Register(app, api.Service{
GRPC: func(s *grpc.Server) { ordersv1.RegisterOrdersServiceServer(s, handler) },
Gateway: ordersv1.RegisterOrdersServiceHandler,
})
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
testapi/platformtest/v1
Package platformtestv1 is a reverse proxy.
|
Package platformtestv1 is a reverse proxy. |