rob05c commented on a change in pull request #3023: WIP Supported routes fetch URL: https://github.com/apache/trafficcontrol/pull/3023#discussion_r233225375
########## File path: traffic_ops/traffic_ops_golang/api/api_route.go ########## @@ -0,0 +1,148 @@ +package api + +/* + * 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 "bytes" +import "net/http" +import "regexp" +import "strconv" +//import trops "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang" +import log "github.com/apache/trafficcontrol/lib/go-log" + +// todo - make the version string modular and accessible everywhere +const ServerString = "Traffic Operations/3.0.0"; +const errorString = "Check the Traffic Ops log file(s) for details\n"; + +var APIVersions []float64; + + +// CompiledRoute ... +type CompiledRoute struct { + Handler http.HandlerFunc + Regex *regexp.Regexp + Params []string +} + + +var AllRoutes *map[string][]CompiledRoute; +// Writes a message indicating an internal server error back to the client (in plain text) +func errorResponse(writer http.ResponseWriter) { + err := []byte(errorString); + writer.Header().Set("Content-Length", strconv.Itoa(len(err))); + writer.WriteHeader(http.StatusInternalServerError); + writer.Write(err); +} + +// Handles the disallowed request methods for this endpoint +func AvailableRoutesBadMethodHandler(writer http.ResponseWriter, request *http.Request) { Review comment: I don't either, but it's idiomatic Go. You see `w http.ResponseWriter` everywhere, in user code and Go itself. Further, the Go style guidelines disagree with us on readability. https://github.com/golang/go/wiki/CodeReviewComments#variable-names Idioms also affect readability. In this case, IMO the idioms of the language take precedence over the general illegibility. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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
