From 2a658e056a8a4ebb9c302b451b0654db32758cf0 Mon Sep 17 00:00:00 2001 From: Mark Nevill Date: Wed, 11 Jan 2017 09:55:41 +0000 Subject: [PATCH] Add proper JSON marshaling of config regexps. --- config/config.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/config.go b/config/config.go index 1a7ba68e93..24c8b42368 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "encoding/json" "github.com/prometheus/common/model" "gopkg.in/yaml.v2" ) @@ -481,3 +482,11 @@ func (re *Regexp) MarshalYAML() (interface{}, error) { } return nil, nil } + +// MarshalJSON implements the json.Marshaler interface. +func (re Regexp) MarshalJSON() ([]byte, error) { + if re.Regexp != nil { + return json.Marshal(re.String()) + } + return nil, nil +}