jagan-parthiban commented on code in PR #7545:
URL: https://github.com/apache/trafficcontrol/pull/7545#discussion_r1229860300
##########
lib/go-tc/stats_summary.go:
##########
@@ -187,3 +187,148 @@ type StatsSummaryLastUpdatedAPIResponse struct {
Response StatsSummaryLastUpdated `json:"response"`
Alerts
}
+
+// StatsSummaryV5 is an alias for the latest minor version for the major
version 5.
+type StatsSummaryV5 StatsSummaryV50
+
+// StatsSummaryV50 is a summary of some kind of statistic for a CDN and/or
+// Delivery Service.
+type StatsSummaryV50 struct {
+ CDNName *string `json:"cdnName" db:"cdn_name"`
+ DeliveryService *string `json:"deliveryServiceName"
db:"deliveryservice_name"`
+ StatName *string `json:"statName" db:"stat_name"`
+ StatValue *float64 `json:"statValue" db:"stat_value"`
+ SummaryTime time.Time `json:"summaryTime" db:"summary_time"`
+ StatDate *time.Time `json:"statDate" db:"stat_date"`
+}
+
+// Validate implements the
+//
github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api.ParseValidator
+// interface.
+func (ss StatsSummaryV5) Validate(tx *sql.Tx) error {
+ errs := tovalidate.ToErrors(validation.Errors{
+ "statName": validation.Validate(ss.StatName,
validation.Required),
+ "statValue": validation.Validate(ss.StatValue,
validation.Required),
+ })
+ return util.JoinErrs(errs)
+}
+
+// UnmarshalJSON implements the encoding/json.Unmarshaler interface with a
+// customized decoding to force the date format on StatDate.
+func (ss *StatsSummaryV5) UnmarshalJSON(data []byte) error {
+ type Alias StatsSummary
+ resp := struct {
+ SummaryTime string `json:"summaryTime"`
+ StatDate *string `json:"statDate"`
+ *Alias
+ }{
+ Alias: (*Alias)(ss),
+ }
+ err := json.Unmarshal(data, &resp)
+ if err != nil {
+ return err
+ }
+ if resp.StatDate != nil {
+ statDate, err := parseTimeV5(*resp.StatDate)
+ if err != nil {
+ return errors.New("invalid timestamp given for
statDate")
Review Comment:
Fixed It
##########
lib/go-tc/stats_summary.go:
##########
@@ -187,3 +187,148 @@ type StatsSummaryLastUpdatedAPIResponse struct {
Response StatsSummaryLastUpdated `json:"response"`
Alerts
}
+
+// StatsSummaryV5 is an alias for the latest minor version for the major
version 5.
+type StatsSummaryV5 StatsSummaryV50
+
+// StatsSummaryV50 is a summary of some kind of statistic for a CDN and/or
+// Delivery Service.
+type StatsSummaryV50 struct {
+ CDNName *string `json:"cdnName" db:"cdn_name"`
+ DeliveryService *string `json:"deliveryServiceName"
db:"deliveryservice_name"`
+ StatName *string `json:"statName" db:"stat_name"`
+ StatValue *float64 `json:"statValue" db:"stat_value"`
+ SummaryTime time.Time `json:"summaryTime" db:"summary_time"`
+ StatDate *time.Time `json:"statDate" db:"stat_date"`
+}
+
+// Validate implements the
+//
github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api.ParseValidator
+// interface.
+func (ss StatsSummaryV5) Validate(tx *sql.Tx) error {
+ errs := tovalidate.ToErrors(validation.Errors{
+ "statName": validation.Validate(ss.StatName,
validation.Required),
+ "statValue": validation.Validate(ss.StatValue,
validation.Required),
+ })
+ return util.JoinErrs(errs)
+}
+
+// UnmarshalJSON implements the encoding/json.Unmarshaler interface with a
+// customized decoding to force the date format on StatDate.
+func (ss *StatsSummaryV5) UnmarshalJSON(data []byte) error {
+ type Alias StatsSummary
+ resp := struct {
+ SummaryTime string `json:"summaryTime"`
+ StatDate *string `json:"statDate"`
+ *Alias
+ }{
+ Alias: (*Alias)(ss),
+ }
+ err := json.Unmarshal(data, &resp)
+ if err != nil {
+ return err
+ }
+ if resp.StatDate != nil {
+ statDate, err := parseTimeV5(*resp.StatDate)
+ if err != nil {
+ return errors.New("invalid timestamp given for
statDate")
+ }
+ ss.StatDate = &statDate
+ }
+
+ ss.SummaryTime, err = parseTimeV5(resp.SummaryTime)
+ if err != nil {
+ return errors.New("invalid timestamp given for summaryTime")
Review Comment:
Fixed It
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]