alficles commented on a change in pull request #3875: Add TO Go ATS CDN configs
URL: https://github.com/apache/trafficcontrol/pull/3875#discussion_r321472119
 
 

 ##########
 File path: lib/go-atscfg/atscfg.go
 ##########
 @@ -0,0 +1,114 @@
+package atscfg
+
+/*
+ * 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 (
+       "errors"
+       "strconv"
+       "strings"
+       "time"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+// TODO move in config gen PR
+const InvalidID = -1
+
+const HeaderCommentDateFormat = "Mon Jan 2 15:04:05 MST 2006"
+
+type ServerInfo struct {
+       CacheGroupID                  int
+       CDN                           tc.CDNName
+       CDNID                         int
+       DomainName                    string
+       HostName                      string
+       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 HeaderCommentWithTOVersionStr(name string, nameVersionStr string) string {
+       return "# DO NOT EDIT - Generated for " + name + " by " + 
nameVersionStr + " on " + time.Now().Format(HeaderCommentDateFormat) + "\n"
+}
+
+func GetNameVersionStringFromToolNameAndURL(toolName string, url string) 
string {
+       return toolName + " (" + url + ")"
+}
+
+func GenericHeaderComment(name string, toolName string, url string) string {
+       return HeaderCommentWithTOVersionStr(name, 
GetNameVersionStringFromToolNameAndURL(toolName, url))
+}
+
+// GetATSMajorVersionFromATSVersion returns the major version of the given 
profile's package trafficserver parameter.
+// The atsVersion is typically a Parameter on the Server's Profile, with the 
configFile "package" name "trafficserver".
+// Returns an error if atsVersion is empty or not a number.
+func GetATSMajorVersionFromATSVersion(atsVersion string) (int, error) {
+       if len(atsVersion) == 0 {
+               return 0, errors.New("ats version missing")
+       }
+       atsMajorVer, err := strconv.Atoi(atsVersion[:1])
 
 Review comment:
   I am totally aware that this is exactly how perl does it, because I objected 
when I saw the perl version as well. But this would be a delightful opportunity 
to not re-write the bug that is going to happen when ATS 10 is released...

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to