diff --git a/go.mod b/go.mod index 1e3edbbc1..db030be2b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/fvbommel/sortorder v1.1.0 github.com/go-chi/chi/v5 v5.2.5 github.com/go-chi/cors v1.2.2 - github.com/go-json-experiment/json v0.0.0-20260504200034-64a0a05799db + github.com/go-json-experiment/json v0.0.0-20260520185125-572e7c383686 github.com/go-viper/mapstructure/v2 v2.5.0 github.com/google/go-cmp v0.7.0 github.com/hashicorp/golang-lru/v2 v2.0.7 diff --git a/go.sum b/go.sum index f8de8aed8..61d86073d 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= github.com/go-chi/cors v1.2.2 h1:Jmey33TE+b+rB7fT8MUy1u0I4L+NARQlK6LhzKPSyQE= github.com/go-chi/cors v1.2.2/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= -github.com/go-json-experiment/json v0.0.0-20260504200034-64a0a05799db h1:EWTZKWQtY8ZehowJ8hV1E0GJEBiL2a0eJ7Zd/CU448w= -github.com/go-json-experiment/json v0.0.0-20260504200034-64a0a05799db/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg= +github.com/go-json-experiment/json v0.0.0-20260520185125-572e7c383686 h1:NZBJxCpbHS1gzS6xAmyxbJznosZIIPk9IB42v62UvKA= +github.com/go-json-experiment/json v0.0.0-20260520185125-572e7c383686/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg= github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= diff --git a/internal/config/models.go b/internal/config/models.go index cde9eabb5..32fe9f71a 100644 --- a/internal/config/models.go +++ b/internal/config/models.go @@ -3,6 +3,9 @@ package config import ( "regexp" "time" + + jsonv2 "github.com/go-json-experiment/json" + "github.com/go-json-experiment/json/jsontext" ) type AlertmanagerCORS struct { @@ -217,16 +220,30 @@ type configSchema struct { DefaultAlertmanagers []string `yaml:"defaultAlertmanagers" koanf:"defaultAlertmanagers"` } `yaml:"silenceForm" koanf:"silenceForm"` // nolint: maligned - UI struct { - Refresh time.Duration `json:",format:nano"` - HideFiltersWhenIdle bool `yaml:"hideFiltersWhenIdle" koanf:"hideFiltersWhenIdle"` - ColorTitlebar bool `yaml:"colorTitlebar" koanf:"colorTitlebar"` - Theme string `yaml:"theme" koanf:"theme"` - Animations bool `yaml:"animations" koanf:"animations"` - MinimalGroupWidth int `yaml:"minimalGroupWidth" koanf:"minimalGroupWidth"` - AlertsPerGroup int `yaml:"alertsPerGroup" koanf:"alertsPerGroup"` - CollapseGroups string `yaml:"collapseGroups" koanf:"collapseGroups"` - MultiGridLabel string `yaml:"multiGridLabel" koanf:"multiGridLabel"` - MultiGridSortReverse bool `yaml:"multiGridSortReverse" koanf:"multiGridSortReverse"` + UI UIConfig +} + +type UIConfig struct { + Refresh time.Duration `json:"Refresh"` + HideFiltersWhenIdle bool `yaml:"hideFiltersWhenIdle" koanf:"hideFiltersWhenIdle"` + ColorTitlebar bool `yaml:"colorTitlebar" koanf:"colorTitlebar"` + Theme string `yaml:"theme" koanf:"theme"` + Animations bool `yaml:"animations" koanf:"animations"` + MinimalGroupWidth int `yaml:"minimalGroupWidth" koanf:"minimalGroupWidth"` + AlertsPerGroup int `yaml:"alertsPerGroup" koanf:"alertsPerGroup"` + CollapseGroups string `yaml:"collapseGroups" koanf:"collapseGroups"` + MultiGridLabel string `yaml:"multiGridLabel" koanf:"multiGridLabel"` + MultiGridSortReverse bool `yaml:"multiGridSortReverse" koanf:"multiGridSortReverse"` +} + +func (ui UIConfig) MarshalJSON() ([]byte, error) { + type uiAlias UIConfig + aux := struct { + uiAlias + Refresh int64 `json:"Refresh"` + }{ + uiAlias: uiAlias(ui), + Refresh: int64(ui.Refresh), } + return jsonv2.Marshal(aux, jsontext.EscapeForHTML(true)) }