ocket8888 commented on a change in pull request #5337:
URL: https://github.com/apache/trafficcontrol/pull/5337#discussion_r533627142



##########
File path: traffic_ops_ort/t3c-diff-tool/t3c-diff-tool.go
##########
@@ -0,0 +1,72 @@
+package main
+
+/*
+ * 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 (
+       "fmt"
+       "os"
+       "regexp"
+       "strings"
+
+       "github.com/apache/trafficcontrol/traffic_ops_ort/t3cutil"
+       "github.com/kylelemons/godebug/diff"

Review comment:
       New dependencies must be vendored

##########
File path: traffic_ops_ort/t3c-diff-tool/t3c-diff-tool.go
##########
@@ -0,0 +1,72 @@
+package main
+
+/*
+ * 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 (
+       "fmt"
+       "os"
+       "regexp"
+       "strings"
+
+       "github.com/apache/trafficcontrol/traffic_ops_ort/t3cutil"
+       "github.com/kylelemons/godebug/diff"
+       "github.com/pborman/getopt/v2"
+)
+
+func main() {
+       different := false
+       tropsFile := getopt.StringLong("trops-file", 't', "", "Required: Config 
file name in Traffic Ops")
+       diskFile := getopt.StringLong("disk-file", 'd', "", "Required: Config 
file on disk")

Review comment:
       If you make these true [Mandatory 
Options](https://godoc.org/github.com/pborman/getopt/v2#hdr-MANDATORY_OPTIONS), 
you won't need to check them yourself.

##########
File path: traffic_ops_ort/t3cutil/t3cutil.go
##########
@@ -0,0 +1,91 @@
+package t3cutil
+
+/*
+ * 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 (
+       "fmt"
+       "io/ioutil"
+       "os"
+       "regexp"
+       "strings"
+)
+
+// commentsFilter is used to remove comment
+// lines from config files while making
+// comparisons.
+func CommentsFilter(body []string) []string {
+       var newlines []string
+
+       newlines = make([]string, 0)
+
+       for ii := range body {
+               line := body[ii]
+               if strings.HasPrefix(line, "#") {
+                       continue
+               }
+               newlines = append(newlines, line)
+       }
+
+       return newlines
+}
+
+// NewLineFilter removes carriage returns
+// from config files while making comparisons.
+func NewLineFilter(str string) string {
+       str = strings.ReplaceAll(str, "\r\n", "\n")
+       return strings.TrimSpace(str)
+}
+
+// ReadFile reads a file and returns the
+// file contents.
+func ReadFile(f string) []byte {
+       data, err := ioutil.ReadFile(f)
+       if err != nil {
+               fmt.Println("Error reading file ", f)
+               os.Exit(1)
+       }
+       return data
+}
+
+// UnencodeFilter translates HTML escape
+// sequences while making config file comparisons.
+func UnencodeFilter(body []string) []string {
+       var newlines []string
+
+       newlines = make([]string, 0)
+       sp := regexp.MustCompile(`\s+`)
+       el := regexp.MustCompile(`^\s+|\s+$`)
+       am := regexp.MustCompile(`amp;`)
+       lt := regexp.MustCompile(`<`)
+       gt := regexp.MustCompile(`>`)
+
+       for ii := range body {
+               s := body[ii]
+               s = sp.ReplaceAllString(s, " ")
+               s = el.ReplaceAllString(s, "")
+               s = am.ReplaceAllString(s, "")
+               s = lt.ReplaceAllString(s, "<")
+               s = gt.ReplaceAllString(s, ">")
+               s = strings.TrimSpace(s)
+               newlines = append(newlines, s)
+       }
+
+       return newlines
+}

Review comment:
       This is available as [a function in the Go standard 
library](https://godoc.org/html#UnescapeString)

##########
File path: traffic_ops_ort/t3cutil/t3cutil.go
##########
@@ -0,0 +1,91 @@
+package t3cutil
+
+/*
+ * 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 (
+       "fmt"
+       "io/ioutil"
+       "os"
+       "regexp"
+       "strings"
+)
+
+// commentsFilter is used to remove comment
+// lines from config files while making
+// comparisons.
+func CommentsFilter(body []string) []string {
+       var newlines []string
+
+       newlines = make([]string, 0)

Review comment:
       If you're going to use `make`, you could pass it a third parameter to 
pre-allocate space, which would speed things up.




----------------------------------------------------------------
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]


Reply via email to