Add interfaces for supporting ExtendedAttributes.
This commit adds some methods to CheckConfig that allow Marshaling,
Unmarshaling and querying extended attributes.
Refs
@@ -5,6 +5,8 @@ import (
"fmt"
"sort"
"time"
+
+ "github.com/sensu/sensu-go/types/dynamic"
)
// CheckRequestType is the message type string for check request.
@@ -25,6 +27,26 @@ func (c *Check) Validate() error {
return nil
}
+// UnmarshalJSON implements the json.Unmarshaler interface.
+func (c *CheckConfig) UnmarshalJSON(b []byte) error {
+ return dynamic.Unmarshal(b, c)
+}
+
+// MarshalJSON implements the json.Marshaler interface.
+func (c *CheckConfig) MarshalJSON() ([]byte, error) {
+ return dynamic.Marshal(c)
+}
+
+// SetExtendedAttributes sets the serialized ExtendedAttributes of c.
+func (c *CheckConfig) SetExtendedAttributes(e []byte) {
+ c.ExtendedAttributes = e
+}
+
+// Get implements govaluate.Parameters
+func (c *CheckConfig) Get(name string) (interface{}, error) {
+ return dynamic.GetField(c, name)
+}
+
// Validate returns an error if the check does not pass validation tests.
func (c *CheckConfig) Validate() error {
if err := ValidateName(c.Name); err != nil {
