Application Start#
Recall that our program's entrypoint finishes with initializing the app struct and calling the app.Start(ctx)
function. The Start
function is a place where we start the application's lifecycle.
greeter/app.go
func (a *App) Start(ctx context.Context) {
go a.receiveConfigNotifications(ctx)
for {
select {
case <-a.configReceivedCh:
a.logger.Info().Msg("Received full config")
a.processConfig(ctx)
a.updateState(ctx)
case <-ctx.Done():
a.stop()
return
}
}
}
The Start
function is composed of the following parts:
- Start receiving configuration notifications with
receiveConfigNotifications
function. In this function we:- Start Configuration Stream
- Receive notifications from the stream
- When the configuration notification is received, unmarshal received config into the
ConfigState
struct - Upon "commit.end" marker seen in the config notification, signal that the whole config set has been read by sending a message to the
receivedCh
channel
- Process the configuration by computing the
greeting
value - Update application's state by with
name
andgreeting
values - Stop the application when the context is cancelled
Here the major difference with the Bond-based approach is that we have to manually handle the configuration notifications.
Time to have a closer look at the first part of the Start
function - receiving configuration notifications with go a.receiveConfigNotifications(ctx)
function.