/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/services/ngalert/models/instance_annotations.go
34 строки
829 B
Alexander Akhmetov
Alerting: Store instance annotations in alert rule state (#114975)
09 дек 2025, 15:52
Не верифицирован
09 дек 2025, 15:52
c59d5d1
Код
Авторство
О чём код?
package models import ( "encoding/json" ) // InstanceAnnotations is an extension to map[string]string with methods // for database serialization. type InstanceAnnotations map[string]string // FromDB loads annotations stored in the database as JSON into InstanceAnnotations. // FromDB is part of the xorm Conversion interface. func (a *InstanceAnnotations) FromDB(b []byte) error { if len(b) == 0 { *a = nil return nil } annotations := make(map[string]string) err := json.Unmarshal(b, &annotations) if err != nil { return err } *a = annotations return nil } // ToDB serializes InstanceAnnotations to JSON for database storage. // ToDB is part of the xorm Conversion interface. func (a *InstanceAnnotations) ToDB() ([]byte, error) { if a == nil || len(*a) == 0 { return nil, nil } return json.Marshal(*a) }