github.com/newrelic/newrelic-client-go@v1.1.0/pkg/alerts/serialization.go (about)

     1  package alerts
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  )
     7  
     8  // UnmarshalJSON is responsible for unmarshaling the ConditionTerm type.
     9  func (c *ConditionTerm) UnmarshalJSON(data []byte) error {
    10  	var v map[string]interface{}
    11  	if err := json.Unmarshal(data, &v); err != nil {
    12  		return err
    13  	}
    14  
    15  	threshold, err := strconv.ParseFloat(v["threshold"].(string), 64)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	duration, err := strconv.ParseInt(v["duration"].(string), 10, 32)
    21  	if err != nil {
    22  		return err
    23  	}
    24  
    25  	c.Threshold = threshold
    26  	c.Duration = int(duration)
    27  	c.Operator = OperatorType(v["operator"].(string))
    28  	c.Priority = PriorityType(v["priority"].(string))
    29  	c.TimeFunction = TimeFunctionType(v["time_function"].(string))
    30  
    31  	return nil
    32  }