@@ -4,11 +4,12 @@ import (
4
4
"context"
5
5
"embed"
6
6
"fmt"
7
- "github.com/labstack/echo/v4"
8
7
"net/http"
9
8
"strconv"
10
9
"strings"
11
10
11
+ "github.com/labstack/echo/v4"
12
+
12
13
"github.com/ankorstore/yokai/config"
13
14
"github.com/ankorstore/yokai/fxconfig"
14
15
"github.com/ankorstore/yokai/fxgenerate"
@@ -234,12 +235,24 @@ func withMiddlewares(coreServer *echo.Echo, p FxCoreParam) *echo.Echo {
234
235
func withHandlers (coreServer * echo.Echo , p FxCoreParam ) (* echo.Echo , error ) {
235
236
appDebug := p .Config .AppDebug ()
236
237
237
- // overview
238
- info , err := p .Registry .Find (ModuleName )
238
+ // dashboard
239
+ dashboardEnabled := p .Config .GetBool ("modules.core.server.dashboard.enabled" )
240
+
241
+ // dashboard overview
242
+ overviewInfo , err := p .Registry .Find (ModuleName )
239
243
if err != nil {
240
244
return nil , err
241
245
}
242
246
247
+ // dashboard overview expositions
248
+ overviewAppEnvExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.app_env" )
249
+ overviewAppDebugExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.app_debug" )
250
+ overviewAppVersionExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.app_version" )
251
+ overviewLogLevelExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.log_level" )
252
+ overviewLogOutputExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.log_output" )
253
+ overviewTraceSamplerExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.trace_sampler" )
254
+ overviewTraceProcessorExpose := p .Config .GetBool ("modules.core.server.dashboard.overview.trace_processor" )
255
+
243
256
// template expositions
244
257
metricsExpose := p .Config .GetBool ("modules.core.server.metrics.expose" )
245
258
startupExpose := p .Config .GetBool ("modules.core.server.healthcheck.startup.expose" )
@@ -404,75 +417,87 @@ func withHandlers(coreServer *echo.Echo, p FxCoreParam) (*echo.Echo, error) {
404
417
coreServer .Logger .Debug ("registered debug modules handler" )
405
418
}
406
419
407
- // theme
408
- coreServer .POST ("/theme" , func (c echo.Context ) error {
409
- themeCookie := new (http.Cookie )
410
- themeCookie .Name = "theme"
411
-
412
- var theme FxCoreDashboardTheme
413
- if err = c .Bind (& theme ); err != nil {
414
- themeCookie .Value = ThemeLight
415
- } else {
416
- switch theme .Theme {
417
- case ThemeDark :
418
- themeCookie .Value = ThemeDark
419
- case ThemeLight :
420
- themeCookie .Value = ThemeLight
421
- default :
420
+ // dashboard
421
+ if dashboardEnabled || appDebug {
422
+ // theme
423
+ coreServer .POST ("/theme" , func (c echo.Context ) error {
424
+ themeCookie := new (http.Cookie )
425
+ themeCookie .Name = "theme"
426
+
427
+ var theme FxCoreDashboardTheme
428
+ if err = c .Bind (& theme ); err != nil {
422
429
themeCookie .Value = ThemeLight
430
+ } else {
431
+ switch theme .Theme {
432
+ case ThemeDark :
433
+ themeCookie .Value = ThemeDark
434
+ case ThemeLight :
435
+ themeCookie .Value = ThemeLight
436
+ default :
437
+ themeCookie .Value = ThemeLight
438
+ }
423
439
}
424
- }
425
440
426
- c .SetCookie (themeCookie )
441
+ c .SetCookie (themeCookie )
427
442
428
- return c .Redirect (http .StatusMovedPermanently , "/" )
429
- })
443
+ return c .Redirect (http .StatusMovedPermanently , "/" )
444
+ })
430
445
431
- // dashboard
432
- coreServer .GET ("/" , func (c echo.Context ) error {
433
- var theme string
434
- themeCookie , err := c .Cookie ("theme" )
435
- if err == nil {
436
- switch themeCookie .Value {
437
- case ThemeDark :
438
- theme = ThemeDark
439
- case ThemeLight :
440
- theme = ThemeLight
441
- default :
446
+ coreServer .Logger .Debug ("registered dashboard theme handler" )
447
+
448
+ // render
449
+ coreServer .GET ("/" , func (c echo.Context ) error {
450
+ var theme string
451
+ themeCookie , err := c .Cookie ("theme" )
452
+ if err == nil {
453
+ switch themeCookie .Value {
454
+ case ThemeDark :
455
+ theme = ThemeDark
456
+ case ThemeLight :
457
+ theme = ThemeLight
458
+ default :
459
+ theme = ThemeLight
460
+ }
461
+ } else {
442
462
theme = ThemeLight
443
463
}
444
- } else {
445
- theme = ThemeLight
446
- }
447
464
448
- return c .Render (http .StatusOK , "dashboard.html" , map [string ]interface {}{
449
- "info" : info ,
450
- "metricsExpose" : metricsExpose ,
451
- "metricsPath" : metricsPath ,
452
- "startupExpose" : startupExpose ,
453
- "startupPath" : startupPath ,
454
- "livenessExpose" : livenessExpose ,
455
- "livenessPath" : livenessPath ,
456
- "readinessExpose" : readinessExpose ,
457
- "readinessPath" : readinessPath ,
458
- "configExpose" : configExpose || appDebug ,
459
- "configPath" : configPath ,
460
- "pprofExpose" : pprofExpose || appDebug ,
461
- "pprofPath" : pprofPath ,
462
- "routesExpose" : routesExpose || appDebug ,
463
- "routesPath" : routesPath ,
464
- "statsExpose" : statsExpose || appDebug ,
465
- "statsPath" : statsPath ,
466
- "buildExpose" : buildExpose || appDebug ,
467
- "buildPath" : buildPath ,
468
- "modulesExpose" : modulesExpose || appDebug ,
469
- "modulesPath" : modulesPath ,
470
- "modulesNames" : p .Registry .Names (),
471
- "theme" : theme ,
465
+ return c .Render (http .StatusOK , "dashboard.html" , map [string ]interface {}{
466
+ "overviewInfo" : overviewInfo ,
467
+ "overviewAppEnvExpose" : overviewAppEnvExpose ,
468
+ "overviewAppDebugExpose" : overviewAppDebugExpose ,
469
+ "overviewAppVersionExpose" : overviewAppVersionExpose ,
470
+ "overviewLogLevelExpose" : overviewLogLevelExpose ,
471
+ "overviewLogOutputExpose" : overviewLogOutputExpose ,
472
+ "overviewTraceSamplerExpose" : overviewTraceSamplerExpose ,
473
+ "overviewTraceProcessorExpose" : overviewTraceProcessorExpose ,
474
+ "metricsExpose" : metricsExpose ,
475
+ "metricsPath" : metricsPath ,
476
+ "startupExpose" : startupExpose ,
477
+ "startupPath" : startupPath ,
478
+ "livenessExpose" : livenessExpose ,
479
+ "livenessPath" : livenessPath ,
480
+ "readinessExpose" : readinessExpose ,
481
+ "readinessPath" : readinessPath ,
482
+ "configExpose" : configExpose || appDebug ,
483
+ "configPath" : configPath ,
484
+ "pprofExpose" : pprofExpose || appDebug ,
485
+ "pprofPath" : pprofPath ,
486
+ "routesExpose" : routesExpose || appDebug ,
487
+ "routesPath" : routesPath ,
488
+ "statsExpose" : statsExpose || appDebug ,
489
+ "statsPath" : statsPath ,
490
+ "buildExpose" : buildExpose || appDebug ,
491
+ "buildPath" : buildPath ,
492
+ "modulesExpose" : modulesExpose || appDebug ,
493
+ "modulesPath" : modulesPath ,
494
+ "modulesNames" : p .Registry .Names (),
495
+ "theme" : theme ,
496
+ })
472
497
})
473
- })
474
498
475
- coreServer .Logger .Debug ("registered debug dashboard handler" )
499
+ coreServer .Logger .Debug ("registered dashboard handler" )
500
+ }
476
501
477
502
return coreServer , nil
478
503
}
0 commit comments