-
Notifications
You must be signed in to change notification settings - Fork 4
Startup
Before catering for web requests the service needs to be started. Catalyst starts itself by executing following steps in order.
- Parse configurations
- Resolve Container
- Initialize Router
- Run Server
Configurations are read from a collection of yaml files in a specified directory (by default this directory is at the project root named config). These configurations are stored in a single Config object.
Catalyst uses a simple container to easily manage dependencies and IoC(Inversion of Control). The parsed Config object is passed in to the container resolver which will resolve all dependencies and return a Container object with those resolved dependencies.
The router is initialized by passing in the resolved container.
Once everything is done the web server is started by passing in application configurations, router and the container.
If metrics are enabled in configurations Catalyst will also start a separate Prometheus metric server to expose service metrics.
Steps of the startup process is chained together so that output from one step becomes the input for the next step.
func main() {
// show splash screen when starting
splash.Show(splash.StyleShadow)
// parse all configurations
cfg := config.Parse("./config")
// resolve the container using parsed configurations
ctr := container.Resolve(cfg)
// initialize the router
r := router.Init(ctr)
// start the server to handle requests
server.Run(cfg.AppConfig, r, ctr)
}