This repository has been archived on 2024-02-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
astontest/internal/application/application.go
derfenix 7864272baa Initial version
Project structure, api, discovery service, docker.
2023-12-06 08:32:01 +03:00

43 lines
902 B
Go

package application
import (
"context"
"fmt"
"sync"
"go.uber.org/zap"
"git.derfenix.pro/fenix/astontest/pkg/discovery"
)
type Application struct {
discoverySet discovery.DiscoverySet
log *zap.Logger
}
func NewApplication(cfg *Config, log *zap.Logger) (*Application, error) {
discoveryOpts := []discovery.Option{discovery.WithBroadcastInterval(cfg.BroadcastInterval)}
if cfg.Debug {
discoveryOpts = append(discoveryOpts, discovery.WithDebug())
}
set, err := discovery.NewDiscoverySet(log.Named("discovery"), cfg.DiscoveryPort, discoveryOpts...)
if err != nil {
return nil, fmt.Errorf("new discovery set: %w", err)
}
return &Application{
discoverySet: set,
log: log,
}, nil
}
func (a *Application) Start(ctx context.Context, wg *sync.WaitGroup) {
wg.Add(len(a.discoverySet))
for _, discover := range a.discoverySet {
go discover.Start(ctx, wg)
}
}