mhoppa commented on a change in pull request #3758: Rewrote 
deliveryservice_stats to Go
URL: https://github.com/apache/trafficcontrol/pull/3758#discussion_r328773904
 
 

 ##########
 File path: lib/go-tc/traffic_stats.go
 ##########
 @@ -0,0 +1,148 @@
+package tc
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import "strings"
+
+// TRAFFIC_STATS_VERSION was supposed to be the "API version", but actually 
the plugin (this route
+// used to be a plugin in Perl) always returned this static value
+const TRAFFIC_STATS_VERSION = "1.2"
+
+// TRAFFIC_STATS_SOURCE is the value of the "source" field in an API response. 
Perl always returned
+// source="TrafficStats", so we do too
+const TRAFFIC_STATS_SOURCE = "TrafficStats"
+
+// TrafficStatsDuration reflects all the possible durations that can be 
requested via the
+// deliveryservice_stats endpoint
+type TrafficStatsDuration string
+
+const (
+       InvalidDuration TrafficStatsDuration = ""
+       OneMinute       TrafficStatsDuration = "1m"
+       FiveMinutes     TrafficStatsDuration = "5m"
+       OneHour         TrafficStatsDuration = "1h"
+       SixHours        TrafficStatsDuration = "6h"
+       OneDay          TrafficStatsDuration = "1d"
+       OneWeek         TrafficStatsDuration = "1w"
+       OneMonth        TrafficStatsDuration = "4w"
+)
+
+// TrafficStatsDurationFromString converts the given string into the 
appropriate
+// TrafficStatsDuration if possible - returns the InvalidDuration constant if 
not.
+func TrafficStatsDurationFromString(v string) TrafficStatsDuration {
+       switch TrafficStatsDuration(strings.Trim(v, " ")) {
+       case OneMinute:
+               return OneMinute
+       case FiveMinutes:
+               return FiveMinutes
+       case OneHour:
+               return OneHour
+       case SixHours:
+               return SixHours
+       case OneDay:
+               return OneDay
+       case OneWeek:
+               return OneWeek
+       case OneMonth:
+               return OneMonth
+       }
+       return InvalidDuration
+}
+
+// Seconds returns the number of seconds to which a TrafficStatsDuration is 
equivalent.
+// For invalid objects, it returns -1 - otherwise it will always, of course be 
> 0.
+func (d TrafficStatsDuration) Seconds() int64 {
+       switch d {
 
 Review comment:
   not better I personally just like it better for readability and adding new 
values to going forward. But that is just an opinion hence the nit/question :) 
leave as is 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to