Servers
Start a long-running server through the runtime.
If the component graph contains a runtime.Server, Procyon treats the
application as a long-running server process. The server starts after
configuration, component initialization, and lifecycle startup have completed.
type AppServer struct {
port int
}
func NewAppServer() *AppServer {
return &AppServer{port: 8080}
}
func (s *AppServer) Start(ctx context.Context) error {
return nil
}
func (s *AppServer) Stop(ctx context.Context) error {
return nil
}
func (s *AppServer) Port() int {
return s.port
}Register the server like any other component:
func init() {
component.Register(NewAppServer)
}Server startup
Server startup happens after configuration, context initialization, container refresh, command-line runners, and lifecycle startup. That means the server can depend on configured services and other registered components.
This is the main reason to model the server as a component: the server does not need to know how to build repositories, route handlers, middleware, or typed configuration. Those dependencies are already available by the time the server starts.
Shutdown
The runtime calls Stop during shutdown so the server can close listeners,
flush pending work, or release resources.
Keep shutdown code graceful. The runtime waits for SIGINT or SIGTERM for
server applications, then closes the context and gives server/lifecycle
components a chance to stop.
