Github user dewrich commented on a diff in the pull request:
https://github.com/apache/incubator-trafficcontrol/pull/799#discussion_r133025171
--- Diff: traffic_ops/traffic_ops_golang/routes.go ---
@@ -25,21 +25,37 @@ import (
"fmt"
"net/http"
"net/http/httputil"
- "regexp"
- "strings"
)
-type ServerData struct {
- Config
- DB *sql.DB
+// Routes returns the routes, and a catchall route for when no route
matches.
+func Routes(d ServerData) ([]Route, http.Handler, error) {
+ rd, err := routeData(d)
+ if err != nil {
+ return nil, nil, err
+ }
+ return []Route{
+ {1.2, http.MethodGet, "cdns/{cdn}/configs/monitoring",
wrapHeaders(wrapAuth(monitoringHandler(d.DB), d.Insecure, d.TOSecret,
rd.PrivLevelStmt, MonitoringPrivLevel))},
+ {1.2, http.MethodGet, "cdns/{cdn}/configs/monitoring.json",
wrapHeaders(wrapAuth(monitoringHandler(d.DB), d.Insecure, d.TOSecret,
rd.PrivLevelStmt, MonitoringPrivLevel))},
+ }, rootHandler(d), nil
+}
+
+type RouteData struct {
+ PrivLevelStmt *sql.Stmt
}
-type ParamMap map[string]string
+func routeData(d ServerData) (RouteData, error) {
+ rd := RouteData{}
+ err := error(nil)
-type RegexHandlerFunc func(w http.ResponseWriter, r *http.Request, params
ParamMap)
+ if rd.PrivLevelStmt, err = preparePrivLevelStmt(d.DB); err != nil {
+ return rd, fmt.Errorf("Error preparing db priv level query: ",
err)
+ }
+
+ return rd, nil
+}
// getRootHandler returns the / handler for the service, which
reverse-proxies the old Perl Traffic Ops
-func getRootHandler(d ServerData) http.Handler {
+func rootHandler(d ServerData) http.Handler {
--- End diff --
Glad you renamed that, I wasn't a fan of the `getRootHandler` function name
as well
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---