Refactor structs to use map[string]string

This commit is contained in:
Thorben Günther 2023-02-12 14:40:32 +01:00
parent 1b986078f0
commit 7bb448b5eb
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED
2 changed files with 13 additions and 13 deletions

20
main.go
View file

@ -30,19 +30,19 @@ type receiver struct {
} }
type payload struct { type payload struct {
Status string `json:"status"` Status string `json:"status"`
Alerts []alert `json:"alerts"` Alerts []alert `json:"alerts"`
GroupLabels map[string]interface{} `json:"groupLabels"` GroupLabels map[string]string `json:"groupLabels"`
CommonLabels map[string]interface{} `json:"commonLabels"` CommonLabels map[string]string `json:"commonLabels"`
CommonAnnotations map[string]interface{} `json:"commonAnnotations"` CommonAnnotations map[string]string `json:"commonAnnotations"`
ExternalURL string `json:"externalURL"` ExternalURL string `json:"externalURL"`
} }
type alert struct { type alert struct {
Status string `json:"status"` Status string `json:"status"`
Labels map[string]interface{} `json:"labels"` Labels map[string]string `json:"labels"`
Annotations map[string]interface{} `json:"annotations"` Annotations map[string]string `json:"annotations"`
Fingerprint fingerprint `json:"fingerprint"` Fingerprint fingerprint `json:"fingerprint"`
} }
type notification struct { type notification struct {

View file

@ -28,8 +28,8 @@ type matcher struct {
} }
type silenceBody struct { type silenceBody struct {
AlertManagerURL string `json:"alertmanagerURL"` AlertManagerURL string `json:"alertmanagerURL"`
Labels map[string]interface{} `json:"labels"` Labels map[string]string `json:"labels"`
} }
func (rcv *receiver) handleSilences(w http.ResponseWriter, r *http.Request) { func (rcv *receiver) handleSilences(w http.ResponseWriter, r *http.Request) {
@ -64,7 +64,7 @@ func (rcv *receiver) handleSilences(w http.ResponseWriter, r *http.Request) {
for key, value := range sb.Labels { for key, value := range sb.Labels {
m := matcher{ m := matcher{
Name: key, Name: key,
Value: value.(string), Value: value,
IsRegex: false, IsRegex: false,
IsEqual: true, IsEqual: true,
} }