@@ -4,11 +4,12 @@ import (
44 "context"
55 "embed"
66 "fmt"
7- "github.com/labstack/echo/v4"
87 "net/http"
98 "strconv"
109 "strings"
1110
11+ "github.com/labstack/echo/v4"
12+
1213 "github.com/ankorstore/yokai/config"
1314 "github.com/ankorstore/yokai/fxconfig"
1415 "github.com/ankorstore/yokai/fxgenerate"
@@ -234,12 +235,24 @@ func withMiddlewares(coreServer *echo.Echo, p FxCoreParam) *echo.Echo {
234235func withHandlers (coreServer * echo.Echo , p FxCoreParam ) (* echo.Echo , error ) {
235236 appDebug := p .Config .AppDebug ()
236237
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 )
239243 if err != nil {
240244 return nil , err
241245 }
242246
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+
243256 // template expositions
244257 metricsExpose := p .Config .GetBool ("modules.core.server.metrics.expose" )
245258 startupExpose := p .Config .GetBool ("modules.core.server.healthcheck.startup.expose" )
@@ -404,75 +417,87 @@ func withHandlers(coreServer *echo.Echo, p FxCoreParam) (*echo.Echo, error) {
404417 coreServer .Logger .Debug ("registered debug modules handler" )
405418 }
406419
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 {
422429 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+ }
423439 }
424- }
425440
426- c .SetCookie (themeCookie )
441+ c .SetCookie (themeCookie )
427442
428- return c .Redirect (http .StatusMovedPermanently , "/" )
429- })
443+ return c .Redirect (http .StatusMovedPermanently , "/" )
444+ })
430445
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 {
442462 theme = ThemeLight
443463 }
444- } else {
445- theme = ThemeLight
446- }
447464
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+ })
472497 })
473- })
474498
475- coreServer .Logger .Debug ("registered debug dashboard handler" )
499+ coreServer .Logger .Debug ("registered dashboard handler" )
500+ }
476501
477502 return coreServer , nil
478503}
0 commit comments