mitchell852 closed pull request #2297: Add TO Go cachegroups/trimmed
URL: https://github.com/apache/incubator-trafficcontrol/pull/2297
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lib/go-tc/v13/cachegroups.go b/lib/go-tc/v13/cachegroups.go
index 38ac437ad..ee203fcd5 100644
--- a/lib/go-tc/v13/cachegroups.go
+++ b/lib/go-tc/v13/cachegroups.go
@@ -56,3 +56,7 @@ type CacheGroupNullable struct {
        TypeID                      *int          `json:"typeId" db:"type_id"`  
   // aliased to type_id to disambiguate struct scans due join on 'type' table
        LastUpdated                 *tc.TimeNoMod `json:"lastUpdated" 
db:"last_updated"`
 }
+
+type CachegroupTrimmedName struct {
+       Name string `json:"name"`
+}
diff --git a/traffic_ops/traffic_ops_golang/cachegroup/trimmed.go 
b/traffic_ops/traffic_ops_golang/cachegroup/trimmed.go
new file mode 100644
index 000000000..766c372ec
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/cachegroup/trimmed.go
@@ -0,0 +1,52 @@
+package cachegroup
+
+/*
+ * 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 (
+       "database/sql"
+       "errors"
+       "net/http"
+
+       tc "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+       
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+func TrimmedHandler(db *sql.DB) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               api.RespWriter(w, r)(getCachegroupsTrimmed(db))
+       }
+}
+
+func getCachegroupsTrimmed(db *sql.DB) ([]tc.CachegroupTrimmedName, error) {
+       names := []tc.CachegroupTrimmedName{}
+       rows, err := db.Query(`SELECT name from cachegroup`)
+       if err != nil {
+               return nil, errors.New("selecting cachegroup names: " + 
err.Error())
+       }
+       defer rows.Close()
+       for rows.Next() {
+               name := ""
+               if err := rows.Scan(&name); err != nil {
+                       return nil, errors.New("scanning cachegroup names: " + 
err.Error())
+               }
+               names = append(names, tc.CachegroupTrimmedName{Name: name})
+       }
+       return names, nil
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go 
b/traffic_ops/traffic_ops_golang/routes.go
index 8858c327c..d1822bb06 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -88,6 +88,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, 
error) {
                {1.1, http.MethodDelete, `asns/{id}$`, 
api.DeleteHandler(asn.GetRefTypeV11(), d.DB), auth.PrivLevelOperations, 
Authenticated, nil},
 
                //CacheGroup: CRUD
+               {1.1, http.MethodGet, `cachegroups/trimmed/?(\.json)?$`, 
cachegroup.TrimmedHandler(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
                {1.1, http.MethodGet, `cachegroups/?(\.json)?$`, 
api.ReadHandler(cachegroup.GetRefType(), d.DB), auth.PrivLevelReadOnly, 
Authenticated, nil},
                {1.1, http.MethodGet, `cachegroups/{id}$`, 
api.ReadHandler(cachegroup.GetRefType(), d.DB), auth.PrivLevelReadOnly, 
Authenticated, nil},
                {1.1, http.MethodPut, `cachegroups/{id}$`, 
api.UpdateHandler(cachegroup.GetRefType(), d.DB), auth.PrivLevelOperations, 
Authenticated, nil},


 

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


With regards,
Apache Git Services

Reply via email to