You've already forked management-refactor
mirror of
https://github.com/netbirdio/management-refactor.git
synced 2026-05-22 17:12:59 -07:00
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/netbirdio/management-refactor/internals/controllers/network_map"
|
|
"github.com/netbirdio/management-refactor/internals/shared/db"
|
|
appmetrics "github.com/netbirdio/management-refactor/internals/shared/metrics"
|
|
)
|
|
|
|
type Controller struct {
|
|
repo Repository
|
|
metrics *metrics
|
|
UpdateChannel network_map.UpdateChannel
|
|
}
|
|
|
|
func NewController(store *db.Store, metrics *appmetrics.AppMetrics, updateChannel network_map.UpdateChannel) *Controller {
|
|
cMetrics, err := appmetrics.RegisterMetrics(metrics, newMetrics)
|
|
if err != nil {
|
|
log.Fatalf("Failed to register app metrics: %v", err)
|
|
}
|
|
return &Controller{
|
|
repo: newRepository(store, cMetrics),
|
|
metrics: cMetrics,
|
|
UpdateChannel: updateChannel,
|
|
}
|
|
}
|
|
|
|
func (c *Controller) CalculateNetworkMap(ctx context.Context, accountID string) (*network_map.NetworkMap, error) {
|
|
_, err := c.repo.GetNetworkMapData(accountID)
|
|
if err != nil {
|
|
// usually return error
|
|
}
|
|
|
|
// Do calc on data
|
|
|
|
log.WithContext(ctx).Tracef("Calculating network map for account on public")
|
|
|
|
return &network_map.NetworkMap{}, nil
|
|
}
|
|
|
|
func (c *Controller) UpdatePeers(ctx context.Context, accountID string) error {
|
|
_, err := c.CalculateNetworkMap(ctx, accountID)
|
|
if err != nil {
|
|
log.Errorf("Failed to calculate network map for account %s: %v", accountID, err)
|
|
return err
|
|
}
|
|
c.UpdateChannel.SendUpdate(ctx, accountID, &network_map.UpdateMessage{})
|
|
|
|
return nil
|
|
}
|