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 18:55:10 UTC
[incubator-trafficcontrol] branch master updated (b495be9 ->
233809e)
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git.
from b495be9 Change To Go cg/queue to accept string or int ids
new e28334f Add TO Go Divisions name
new 233809e Change TO Go divisions/name to "CRUDer" interfaces
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
traffic_ops/traffic_ops_golang/division/divisions.go | 4 ++++
traffic_ops/traffic_ops_golang/routes.go | 1 +
2 files changed, 5 insertions(+)
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[incubator-trafficcontrol] 01/02: Add TO Go Divisions name
Posted by el...@apache.org.
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
commit e28334f6429301aa9b76fab6f9f6b61175f8d67c
Author: Robert Butts <ro...@apache.org>
AuthorDate: Tue May 29 14:46:09 2018 -0600
Add TO Go Divisions name
---
.../traffic_ops_golang/division/divisions.go | 24 ++++++++++++++++++++++
traffic_ops/traffic_ops_golang/routes.go | 1 +
2 files changed, 25 insertions(+)
diff --git a/traffic_ops/traffic_ops_golang/division/divisions.go b/traffic_ops/traffic_ops_golang/division/divisions.go
index 260db1d..7d58dbb 100644
--- a/traffic_ops/traffic_ops_golang/division/divisions.go
+++ b/traffic_ops/traffic_ops_golang/division/divisions.go
@@ -23,6 +23,8 @@ import (
"errors"
"fmt"
"strconv"
+ "database/sql"
+ "net/http"
"github.com/apache/incubator-trafficcontrol/lib/go-log"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
@@ -375,3 +377,25 @@ func deleteQuery() string {
WHERE id=:id`
return query
}
+
+func GetName(db *sql.DB) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ params, _, userErr, sysErr, errCode := api.AllParams(r, nil)
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, errCode, userErr, sysErr)
+ return
+ }
+ api.RespWriter(w, r)(getDivisionByName(db, params["name"]))
+ }
+}
+
+func getDivisionByName(db *sql.DB, name string) ([]tc.DivisionNullable, error) {
+ d := tc.DivisionNullable{}
+ if err := db.QueryRow(`SELECT id, name, last_updated from division where name = $1`, name).Scan(&d.ID, &d.Name, &d.LastUpdated); err != nil {
+ if err == sql.ErrNoRows {
+ return []tc.DivisionNullable{}, nil // emulates old Perl behavior; TODO return result error to user?
+ }
+ return nil, errors.New("querying division by name: " + err.Error())
+ }
+ return []tc.DivisionNullable{d}, nil
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 4a898c9..dbdb2bd 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -127,6 +127,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
{1.1, http.MethodPut, `divisions/{id}$`, api.UpdateHandler(division.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodPost, `divisions/?$`, api.CreateHandler(division.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodDelete, `divisions/{id}$`, api.DeleteHandler(division.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
+ {1.1, http.MethodGet, `divisions/name/{name}/?(\.json)?$`, division.GetName(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//HWInfo
{1.1, http.MethodGet, `hwinfo-wip/?(\.json)?$`, hwinfo.HWInfoHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.
[incubator-trafficcontrol] 02/02: Change TO Go divisions/name to
"CRUDer" interfaces
Posted by el...@apache.org.
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
commit 233809e4eeb73e347a6d9ab82d76f52c1a894794
Author: Robert Butts <ro...@apache.org>
AuthorDate: Tue Jun 5 09:36:21 2018 -0600
Change TO Go divisions/name to "CRUDer" interfaces
---
.../traffic_ops_golang/division/divisions.go | 28 ++++------------------
traffic_ops/traffic_ops_golang/routes.go | 2 +-
2 files changed, 5 insertions(+), 25 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/division/divisions.go b/traffic_ops/traffic_ops_golang/division/divisions.go
index 7d58dbb..b1cf2a9 100644
--- a/traffic_ops/traffic_ops_golang/division/divisions.go
+++ b/traffic_ops/traffic_ops_golang/division/divisions.go
@@ -23,8 +23,7 @@ import (
"errors"
"fmt"
"strconv"
- "database/sql"
- "net/http"
+ "strings"
"github.com/apache/incubator-trafficcontrol/lib/go-log"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
@@ -155,6 +154,9 @@ func (division *TODivision) Create(db *sqlx.DB, user auth.CurrentUser) (error, t
}
func (division *TODivision) Read(db *sqlx.DB, parameters map[string]string, user auth.CurrentUser) ([]interface{}, []error, tc.ApiErrorType) {
+ if strings.HasSuffix(parameters["name"], ".json") {
+ parameters["name"] = parameters["name"][:len(parameters["name"]) - len(".json")]
+ }
// Query Parameters to Database Query column mappings
// see the fields mapped in the SQL query
queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
@@ -377,25 +379,3 @@ func deleteQuery() string {
WHERE id=:id`
return query
}
-
-func GetName(db *sql.DB) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- params, _, userErr, sysErr, errCode := api.AllParams(r, nil)
- if userErr != nil || sysErr != nil {
- api.HandleErr(w, r, errCode, userErr, sysErr)
- return
- }
- api.RespWriter(w, r)(getDivisionByName(db, params["name"]))
- }
-}
-
-func getDivisionByName(db *sql.DB, name string) ([]tc.DivisionNullable, error) {
- d := tc.DivisionNullable{}
- if err := db.QueryRow(`SELECT id, name, last_updated from division where name = $1`, name).Scan(&d.ID, &d.Name, &d.LastUpdated); err != nil {
- if err == sql.ErrNoRows {
- return []tc.DivisionNullable{}, nil // emulates old Perl behavior; TODO return result error to user?
- }
- return nil, errors.New("querying division by name: " + err.Error())
- }
- return []tc.DivisionNullable{d}, nil
-}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index dbdb2bd..503440c 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -127,7 +127,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
{1.1, http.MethodPut, `divisions/{id}$`, api.UpdateHandler(division.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodPost, `divisions/?$`, api.CreateHandler(division.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodDelete, `divisions/{id}$`, api.DeleteHandler(division.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
- {1.1, http.MethodGet, `divisions/name/{name}/?(\.json)?$`, division.GetName(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.1, http.MethodGet, `divisions/name/{name}/?(\.json)?$`, api.ReadHandler(division.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//HWInfo
{1.1, http.MethodGet, `hwinfo-wip/?(\.json)?$`, hwinfo.HWInfoHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.