rob05c commented on a change in pull request #5247:
URL: https://github.com/apache/trafficcontrol/pull/5247#discussion_r525491625
##########
File path: lib/go-atscfg/atscfg.go
##########
@@ -22,56 +22,90 @@ package atscfg
import (
"encoding/json"
"errors"
+ "fmt"
"net"
"sort"
"strconv"
"strings"
- "time"
- "github.com/apache/trafficcontrol/lib/go-log"
"github.com/apache/trafficcontrol/lib/go-tc"
)
const InvalidID = -1
-
const DefaultATSVersion = "5" // TODO Emulates Perl; change to 6? ATC no
longer officially supports ATS 5.
-
const HeaderCommentDateFormat = "Mon Jan 2 15:04:05 MST 2006"
-
const ContentTypeTextASCII = `text/plain; charset=us-ascii`
-
const LineCommentHash = "#"
+const ConfigSuffix = ".config"
+
+type DeliveryServiceID int
+type ProfileID int
+type ServerID int
type TopologyName string
type CacheGroupType string
type ServerCapability string
-type ServerInfo struct {
- CacheGroupID int
- CacheGroupName string
- CDN tc.CDNName
- CDNID int
- DomainName string
- HostName string
- HTTPSPort int
- ID int
- IP string
- ParentCacheGroupID int
- ParentCacheGroupType string
- ProfileID ProfileID
- ProfileName string
- Port int
- SecondaryParentCacheGroupID int
- SecondaryParentCacheGroupType string
- Type string
-}
-
-func (s *ServerInfo) IsTopLevelCache() bool {
- return (s.ParentCacheGroupType == tc.CacheGroupOriginTypeName ||
s.ParentCacheGroupID == InvalidID) &&
- (s.SecondaryParentCacheGroupType == tc.CacheGroupOriginTypeName
|| s.SecondaryParentCacheGroupID == InvalidID)
-}
-
-func MakeCGMap(cgs []tc.CacheGroupNullable)
(map[tc.CacheGroupName]tc.CacheGroupNullable, error) {
+// Server is a tc.Server for the latest lib/go-tc and traffic_ops/vx-client
type.
+// This allows atscfg to not have to change the type everywhere it's used,
every time ATC changes the base type,
+// but to only have to change it here, and the places where breaking symbol
changes were made.
+type Server tc.ServerV30
+
+// DeliveryService is a tc.DeliveryService for the latest lib/go-tc and
traffic_ops/vx-client type.
+// This allows atscfg to not have to change the type everywhere it's used,
every time ATC changes the base type,
+// but to only have to change it here, and the places where breaking symbol
changes were made.
+type DeliveryService tc.DeliveryServiceNullableV30
+
+// ToDeliveryServices converts a slice of the latest lib/go-tc and
traffic_ops/vx-client type to the local alias.
+func ToDeliveryServices(dses []tc.DeliveryServiceNullableV30)
[]DeliveryService {
+ ad := []DeliveryService{}
+ for _, ds := range dses {
+ ad = append(ad, DeliveryService(ds))
+ }
+ return ad
+}
+
+// OldToDeliveryServices converts a slice of the old traffic_ops/client type
to the local alias.
+func OldToDeliveryServices(dses []tc.DeliveryServiceNullable)
[]DeliveryService {
+ ad := []DeliveryService{}
+ for _, ds := range dses {
+ upgradedDS :=
tc.DeliveryServiceNullableV30{DeliveryServiceNullableV15:
tc.DeliveryServiceNullableV15(ds)}
+ ad = append(ad, DeliveryService(upgradedDS))
+ }
+ return ad
+}
+
+// ToServers converts a slice of the latest lib/go-tc and
traffic_ops/vx-client type to the local alias.
+func ToServers(servers []tc.ServerV30) []Server {
+ as := []Server{}
+ for _, sv := range servers {
+ as = append(as, Server(sv))
+ }
+ return as
+}
Review comment:
Performance really doesn't matter here. It takes seconds to fetch from
Traffic Ops, and the performance here is on the order of milliseconds at most.
I prefer to avoid `make` to use a unified variable declaration syntax where
performance doesn't matter. I fully support using `make` where it does, but it
really doesn't here.
----------------------------------------------------------------
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]