You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/06/05 16:35:15 UTC
[incubator-trafficcontrol] branch master updated: Add TO Go
phys_locations/trimmed
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new d7e74c3 Add TO Go phys_locations/trimmed
d7e74c3 is described below
commit d7e74c30b0f0bcff534a6808efcede66f052ee65
Author: Robert Butts <ro...@apache.org>
AuthorDate: Wed May 30 16:03:49 2018 -0600
Add TO Go phys_locations/trimmed
---
lib/go-tc/physlocations.go | 4 ++
.../traffic_ops_golang/physlocation/trimmed.go | 51 ++++++++++++++++++++++
traffic_ops/traffic_ops_golang/routes.go | 1 +
3 files changed, 56 insertions(+)
diff --git a/lib/go-tc/physlocations.go b/lib/go-tc/physlocations.go
index 6d957ee..c0c32ee 100644
--- a/lib/go-tc/physlocations.go
+++ b/lib/go-tc/physlocations.go
@@ -60,3 +60,7 @@ type PhysLocationNullable struct {
State *string `json:"state" db:"state"`
Zip *string `json:"zip" db:"zip"`
}
+
+type PhysLocationTrimmed struct {
+ Name string `json:"name"`
+}
diff --git a/traffic_ops/traffic_ops_golang/physlocation/trimmed.go b/traffic_ops/traffic_ops_golang/physlocation/trimmed.go
new file mode 100644
index 0000000..15f293e
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/physlocation/trimmed.go
@@ -0,0 +1,51 @@
+package physlocation
+
+/*
+ * 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"
+
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+func GetTrimmed(db *sql.DB) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ api.RespWriter(w, r)(getTrimmed(db))
+ }
+}
+
+func getTrimmed(db *sql.DB) ([]tc.PhysLocationTrimmed, error) {
+ rows, err := db.Query(`SELECT name FROM phys_location`)
+ if err != nil {
+ return nil, errors.New("querying trimmed physical locations: " + err.Error())
+ }
+ ps := []tc.PhysLocationTrimmed{}
+ for rows.Next() {
+ name := ""
+ if err = rows.Scan(&name); err != nil {
+ return nil, errors.New("scanning trimmed physical locations: " + err.Error())
+ }
+ ps = append(ps, tc.PhysLocationTrimmed{Name: name})
+ }
+ return ps, nil
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 032c80c..ad6fba9 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -141,6 +141,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
//Phys_Location: CRUD
{1.1, http.MethodGet, `phys_locations/?(\.json)?$`, api.ReadHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.1, http.MethodGet, `phys_locations/trimmed/?(\.json)?$`, physlocation.GetTrimmed(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
{1.1, http.MethodGet, `phys_locations/{id}$`, api.ReadHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
{1.1, http.MethodPut, `phys_locations/{id}$`, api.UpdateHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodPost, `phys_locations/?$`, api.CreateHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.