@@ -29,20 +29,20 @@ type StandaloneDaemon struct {
29
29
tel telemetry.Telemetry
30
30
}
31
31
32
- func NewStandaloneDaemon (config * config.Config , zl * log.ZapLogger ) (* StandaloneDaemon , error ) {
32
+ func NewStandaloneDaemon (cfg * config.Config , zl * log.ZapLogger ) (* StandaloneDaemon , error ) {
33
33
fmt .Println ("starting Standalone Retina daemon" )
34
34
sdLogger := zl .Named ("standalone-daemon" )
35
35
36
36
var tel telemetry.Telemetry
37
37
var err error
38
- if config .EnableTelemetry {
38
+ if cfg .EnableTelemetry {
39
39
if buildinfo .ApplicationInsightsID == "" {
40
40
panic ("telemetry enabled, but ApplicationInsightsID is empty" )
41
41
}
42
42
sdLogger .Info ("telemetry enabled" , zap .String ("applicationInsightsID" , buildinfo .ApplicationInsightsID ))
43
43
tel , err = telemetry .NewAppInsightsTelemetryClient ("standalone-retina-agent" , map [string ]string {
44
44
"version" : buildinfo .Version ,
45
- "plugins" : strings .Join (config .EnabledPlugin , `,` ),
45
+ "plugins" : strings .Join (cfg .EnabledPlugin , `,` ),
46
46
})
47
47
if err != nil {
48
48
sdLogger .Error ("failed to create telemetry client" , zap .Error (err ))
@@ -54,62 +54,62 @@ func NewStandaloneDaemon(config *config.Config, zl *log.ZapLogger) (*StandaloneD
54
54
}
55
55
56
56
pMgr , err := pm .NewPluginManager (
57
- config ,
57
+ cfg ,
58
58
tel ,
59
59
)
60
60
if err != nil {
61
- return nil , err
61
+ return nil , fmt . Errorf ( "failed to create plugin manager: %w" , err )
62
62
}
63
63
64
64
// create HTTP server for API server
65
65
httpServer := sm .NewHTTPServer (
66
- config .APIServer .Host ,
67
- config .APIServer .Port ,
66
+ cfg .APIServer .Host ,
67
+ cfg .APIServer .Port ,
68
68
)
69
69
70
70
return & StandaloneDaemon {
71
71
l : sdLogger ,
72
72
httpServer : httpServer ,
73
73
pluginManager : pMgr ,
74
- config : config ,
74
+ config : cfg ,
75
75
tel : tel ,
76
76
}, nil
77
77
}
78
78
79
- func (sm * StandaloneDaemon ) Start () {
80
- sm .l .Info ("Starting standalone daemon" )
79
+ func (sd * StandaloneDaemon ) Start () {
80
+ sd .l .Info ("Starting standalone daemon" )
81
81
82
82
// Start the HTTP server and initialize the cache
83
- if err := sm .httpServer .Init (); err != nil {
84
- sm .l .Error ("failed to start http server" )
83
+ if err := sd .httpServer .Init (); err != nil {
84
+ sd .l .Error ("failed to start http server" )
85
85
}
86
- sm .cache = cache .NewStandaloneCache ()
86
+ sd .cache = cache .NewStandaloneCache ()
87
87
88
88
ctx , cancel := context .WithCancel (context .Background ())
89
89
defer cancel ()
90
90
91
91
// start heartbeat goroutine for application insights
92
- go sm .tel .Heartbeat (ctx , sm .config .TelemetryInterval )
92
+ go sd .tel .Heartbeat (ctx , sd .config .TelemetryInterval )
93
93
94
94
var g * errgroup.Group
95
95
g , ctx = errgroup .WithContext (ctx )
96
96
97
97
g .Go (func () error {
98
- return sm .pluginManager .Start (ctx )
98
+ return sd .pluginManager .Start (ctx )
99
99
})
100
100
g .Go (func () error {
101
- return sm .httpServer .Start (ctx )
101
+ return sd .httpServer .Start (ctx )
102
102
})
103
103
104
104
if err := g .Wait (); err != nil {
105
- sm .l .Panic ("Error running standalone daemon" , zap .Error (err ))
105
+ sd .l .Panic ("Error running standalone daemon" , zap .Error (err ))
106
106
}
107
107
108
- sm .l .Info ("Started standalone daemon" )
108
+ sd .l .Info ("Started standalone daemon" )
109
109
}
110
110
111
- func (sm * StandaloneDaemon ) Stop () {
111
+ func (sd * StandaloneDaemon ) Stop () {
112
112
// Clean up plugin resources
113
- sm .pluginManager .Stop ()
114
- sm .l .Info ("Stopped the standalone daemon" )
113
+ sd .pluginManager .Stop ()
114
+ sd .l .Info ("Stopped the standalone daemon" )
115
115
}
0 commit comments