You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/03/21 14:27:49 UTC
[GitHub] dangogh closed pull request #2020: moved cdns struct into v13 package
dangogh closed pull request #2020: moved cdns struct into v13 package
URL: https://github.com/apache/incubator-trafficcontrol/pull/2020
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/cdns.go b/lib/go-tc/v13/cdns.go
similarity index 66%
rename from lib/go-tc/cdns.go
rename to lib/go-tc/v13/cdns.go
index 5402e2c19..e0c1aa8b8 100644
--- a/lib/go-tc/cdns.go
+++ b/lib/go-tc/v13/cdns.go
@@ -1,4 +1,4 @@
-package tc
+package v13
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -18,25 +18,26 @@ package tc
* specific language governing permissions and limitations
* under the License.
*/
+import "github.com/apache/incubator-trafficcontrol/lib/go-tc"
type CDNsResponse struct {
Response []CDN `json:"response"`
}
type CDN struct {
- DNSSECEnabled bool `json:"dnssecEnabled" db:"dnssec_enabled"`
- DomainName string `json:"domainName" db:"domain_name"`
- ID int `json:"id" db:"id"`
- LastUpdated TimeNoMod `json:"lastUpdated" db:"last_updated"`
- Name string `json:"name" db:"name"`
+ DNSSECEnabled bool `json:"dnssecEnabled" db:"dnssec_enabled"`
+ DomainName string `json:"domainName" db:"domain_name"`
+ ID int `json:"id" db:"id"`
+ LastUpdated tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+ Name string `json:"name" db:"name"`
}
type CDNNullable struct {
- DNSSECEnabled *bool `json:"dnssecEnabled" db:"dnssec_enabled"`
- DomainName *string `json:"domainName" db:"domain_name"`
- ID *int `json:"id" db:"id"`
- LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
- Name *string `json:"name" db:"name"`
+ DNSSECEnabled *bool `json:"dnssecEnabled" db:"dnssec_enabled"`
+ DomainName *string `json:"domainName" db:"domain_name"`
+ ID *int `json:"id" db:"id"`
+ LastUpdated *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+ Name *string `json:"name" db:"name"`
}
// CDNSSLKeysResponse ...
diff --git a/traffic_ops/client/cdn.go b/traffic_ops/client/cdn.go
index d9e20e785..8ed0ee416 100644
--- a/traffic_ops/client/cdn.go
+++ b/traffic_ops/client/cdn.go
@@ -22,6 +22,7 @@ import (
"net/http"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
)
const (
@@ -29,7 +30,7 @@ const (
)
// Create a CDN
-func (to *Session) CreateCDN(cdn tc.CDN) (tc.Alerts, ReqInf, error) {
+func (to *Session) CreateCDN(cdn v13.CDN) (tc.Alerts, ReqInf, error) {
var remoteAddr net.Addr
reqBody, err := json.Marshal(cdn)
@@ -48,7 +49,7 @@ func (to *Session) CreateCDN(cdn tc.CDN) (tc.Alerts, ReqInf, error) {
}
// Update a CDN by ID
-func (to *Session) UpdateCDNByID(id int, cdn tc.CDN) (tc.Alerts, ReqInf, error) {
+func (to *Session) UpdateCDNByID(id int, cdn v13.CDN) (tc.Alerts, ReqInf, error) {
var remoteAddr net.Addr
reqBody, err := json.Marshal(cdn)
@@ -68,7 +69,7 @@ func (to *Session) UpdateCDNByID(id int, cdn tc.CDN) (tc.Alerts, ReqInf, error)
}
// Returns a list of CDNs
-func (to *Session) GetCDNs() ([]tc.CDN, ReqInf, error) {
+func (to *Session) GetCDNs() ([]v13.CDN, ReqInf, error) {
resp, remoteAddr, err := to.request(http.MethodGet, API_v12_CDNs, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
if err != nil {
@@ -76,13 +77,13 @@ func (to *Session) GetCDNs() ([]tc.CDN, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNsResponse
+ var data v13.CDNsResponse
err = json.NewDecoder(resp.Body).Decode(&data)
return data.Response, reqInf, nil
}
// GET a CDN by the CDN id
-func (to *Session) GetCDNByID(id int) ([]tc.CDN, ReqInf, error) {
+func (to *Session) GetCDNByID(id int) ([]v13.CDN, ReqInf, error) {
route := fmt.Sprintf("%s/%d", API_v12_CDNs, id)
resp, remoteAddr, err := to.request(http.MethodGet, route, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -91,7 +92,7 @@ func (to *Session) GetCDNByID(id int) ([]tc.CDN, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNsResponse
+ var data v13.CDNsResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, reqInf, err
}
@@ -100,7 +101,7 @@ func (to *Session) GetCDNByID(id int) ([]tc.CDN, ReqInf, error) {
}
// GET a CDN by the CDN name
-func (to *Session) GetCDNByName(name string) ([]tc.CDN, ReqInf, error) {
+func (to *Session) GetCDNByName(name string) ([]v13.CDN, ReqInf, error) {
url := fmt.Sprintf("%s/name/%s", API_v12_CDNs, name)
resp, remoteAddr, err := to.request(http.MethodGet, url, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -109,7 +110,7 @@ func (to *Session) GetCDNByName(name string) ([]tc.CDN, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNsResponse
+ var data v13.CDNsResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, reqInf, err
}
@@ -131,7 +132,7 @@ func (to *Session) DeleteCDNByID(id int) (tc.Alerts, ReqInf, error) {
return alerts, reqInf, nil
}
-func (to *Session) GetCDNSSLKeys(name string) ([]tc.CDNSSLKeys, ReqInf, error) {
+func (to *Session) GetCDNSSLKeys(name string) ([]v13.CDNSSLKeys, ReqInf, error) {
url := fmt.Sprintf("%s/name/%s/sslkeys", API_v12_CDNs, name)
resp, remoteAddr, err := to.request(http.MethodGet, url, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -140,7 +141,7 @@ func (to *Session) GetCDNSSLKeys(name string) ([]tc.CDNSSLKeys, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNSSLKeysResponse
+ var data v13.CDNSSLKeysResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, reqInf, err
}
@@ -149,27 +150,27 @@ func (to *Session) GetCDNSSLKeys(name string) ([]tc.CDNSSLKeys, ReqInf, error) {
}
// Deprecated: use GetCDNs.
-func (to *Session) CDNs() ([]tc.CDN, error) {
+func (to *Session) CDNs() ([]v13.CDN, error) {
cdns, _, err := to.GetCDNs()
return cdns, err
}
// CDNName gets an array of CDNs
// Deprecated: use GetCDNByName
-func (to *Session) CDNName(name string) ([]tc.CDN, error) {
+func (to *Session) CDNName(name string) ([]v13.CDN, error) {
n, _, err := to.GetCDNByName(name)
return n, err
}
// CDNName gets an array of CDNs
// Deprecated: use GetCDNByName
-func (to *Session) GetCDNName(name string) ([]tc.CDN, error) {
+func (to *Session) GetCDNName(name string) ([]v13.CDN, error) {
n, _, err := to.GetCDNByName(name)
return n, err
}
// Deprecated: use GetCDNSSLKeys
-func (to *Session) CDNSSLKeys(name string) ([]tc.CDNSSLKeys, error) {
+func (to *Session) CDNSSLKeys(name string) ([]v13.CDNSSLKeys, error) {
ks, _, err := to.GetCDNSSLKeys(name)
return ks, err
}
diff --git a/traffic_ops/client/v13/cdn.go b/traffic_ops/client/v13/cdn.go
index 5e4c4d5b2..5b57ac33a 100644
--- a/traffic_ops/client/v13/cdn.go
+++ b/traffic_ops/client/v13/cdn.go
@@ -22,6 +22,7 @@ import (
"net/http"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
)
const (
@@ -29,7 +30,7 @@ const (
)
// Create a CDN
-func (to *Session) CreateCDN(cdn tc.CDN) (tc.Alerts, ReqInf, error) {
+func (to *Session) CreateCDN(cdn v13.CDN) (tc.Alerts, ReqInf, error) {
var remoteAddr net.Addr
reqBody, err := json.Marshal(cdn)
@@ -48,7 +49,7 @@ func (to *Session) CreateCDN(cdn tc.CDN) (tc.Alerts, ReqInf, error) {
}
// Update a CDN by ID
-func (to *Session) UpdateCDNByID(id int, cdn tc.CDN) (tc.Alerts, ReqInf, error) {
+func (to *Session) UpdateCDNByID(id int, cdn v13.CDN) (tc.Alerts, ReqInf, error) {
var remoteAddr net.Addr
reqBody, err := json.Marshal(cdn)
@@ -68,7 +69,7 @@ func (to *Session) UpdateCDNByID(id int, cdn tc.CDN) (tc.Alerts, ReqInf, error)
}
// Returns a list of CDNs
-func (to *Session) GetCDNs() ([]tc.CDN, ReqInf, error) {
+func (to *Session) GetCDNs() ([]v13.CDN, ReqInf, error) {
resp, remoteAddr, err := to.request(http.MethodGet, API_v13_CDNs, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
if err != nil {
@@ -76,13 +77,13 @@ func (to *Session) GetCDNs() ([]tc.CDN, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNsResponse
+ var data v13.CDNsResponse
err = json.NewDecoder(resp.Body).Decode(&data)
return data.Response, reqInf, nil
}
// GET a CDN by the CDN ID
-func (to *Session) GetCDNByID(id int) ([]tc.CDN, ReqInf, error) {
+func (to *Session) GetCDNByID(id int) ([]v13.CDN, ReqInf, error) {
route := fmt.Sprintf("%s/%d", API_v13_CDNs, id)
resp, remoteAddr, err := to.request(http.MethodGet, route, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -91,7 +92,7 @@ func (to *Session) GetCDNByID(id int) ([]tc.CDN, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNsResponse
+ var data v13.CDNsResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, reqInf, err
}
@@ -100,7 +101,7 @@ func (to *Session) GetCDNByID(id int) ([]tc.CDN, ReqInf, error) {
}
// GET a CDN by the CDN name
-func (to *Session) GetCDNByName(name string) ([]tc.CDN, ReqInf, error) {
+func (to *Session) GetCDNByName(name string) ([]v13.CDN, ReqInf, error) {
url := fmt.Sprintf("%s?name=%s", API_v13_CDNs, name)
resp, remoteAddr, err := to.request(http.MethodGet, url, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -109,7 +110,7 @@ func (to *Session) GetCDNByName(name string) ([]tc.CDN, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNsResponse
+ var data v13.CDNsResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, reqInf, err
}
@@ -131,7 +132,7 @@ func (to *Session) DeleteCDNByID(id int) (tc.Alerts, ReqInf, error) {
return alerts, reqInf, nil
}
-func (to *Session) GetCDNSSLKeys(name string) ([]tc.CDNSSLKeys, ReqInf, error) {
+func (to *Session) GetCDNSSLKeys(name string) ([]v13.CDNSSLKeys, ReqInf, error) {
url := fmt.Sprintf("%s/name/%s/sslkeys", API_v13_CDNs, name)
resp, remoteAddr, err := to.request(http.MethodGet, url, nil)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
@@ -140,7 +141,7 @@ func (to *Session) GetCDNSSLKeys(name string) ([]tc.CDNSSLKeys, ReqInf, error) {
}
defer resp.Body.Close()
- var data tc.CDNSSLKeysResponse
+ var data v13.CDNSSLKeysResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, reqInf, err
}
diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go
index 6d3400f57..a350cb1fb 100644
--- a/traffic_ops/testing/api/v13/traffic_control.go
+++ b/traffic_ops/testing/api/v13/traffic_control.go
@@ -15,12 +15,15 @@
package v13
-import tcapi "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+import (
+ tcapi "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+)
// TrafficControl - maps to the tc-fixtures.json file
type TrafficControl struct {
ASNs []tcapi.ASN `json:"asns"`
- CDNs []tcapi.CDN `json:"cdns"`
+ CDNs []v13.CDN `json:"cdns"`
CacheGroups []tcapi.CacheGroup `json:"cachegroups"`
DeliveryServiceRequests []tcapi.DeliveryServiceRequest `json:"deliveryServiceRequests"`
DeliveryServices []tcapi.DeliveryService `json:"deliveryservices"`
diff --git a/traffic_ops/traffic_ops_golang/cdn/cdns.go b/traffic_ops/traffic_ops_golang/cdn/cdns.go
index 3501e67fa..c37e6e9ba 100644
--- a/traffic_ops/traffic_ops_golang/cdn/cdns.go
+++ b/traffic_ops/traffic_ops_golang/cdn/cdns.go
@@ -27,6 +27,7 @@ import (
"github.com/apache/incubator-trafficcontrol/lib/go-log"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
@@ -38,7 +39,7 @@ import (
)
//we need a type alias to define functions on
-type TOCDN tc.CDNNullable
+type TOCDN v13.CDNNullable
//the refType is passed into the handlers where a copy of its type is used to decode the json.
var refType = TOCDN{}
@@ -201,7 +202,7 @@ func (cdn *TOCDN) Read(db *sqlx.DB, parameters map[string]string, user auth.Curr
CDNs := []interface{}{}
for rows.Next() {
- var s tc.CDN
+ var s TOCDN
if err = rows.StructScan(&s); err != nil {
log.Errorf("error parsing CDN rows: %v", err)
return nil, []error{tc.DBError}, tc.SystemError
diff --git a/traffic_ops/traffic_ops_golang/cdn/cdns_test.go b/traffic_ops/traffic_ops_golang/cdn/cdns_test.go
index c514efeb4..7b34fa4e1 100644
--- a/traffic_ops/traffic_ops_golang/cdn/cdns_test.go
+++ b/traffic_ops/traffic_ops_golang/cdn/cdns_test.go
@@ -27,6 +27,7 @@ import (
"time"
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/test"
@@ -35,9 +36,9 @@ import (
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
)
-func getTestCDNs() []tc.CDN {
- cdns := []tc.CDN{}
- testCDN := tc.CDN{
+func getTestCDNs() []v13.CDN {
+ cdns := []v13.CDN{}
+ testCDN := v13.CDN{
DNSSECEnabled: false,
DomainName: "domainName",
ID: 1,
@@ -67,7 +68,7 @@ func TestReadCDNs(t *testing.T) {
refType := GetRefType()
testCDNs := getTestCDNs()
- cols := test.ColsFromStructByTag("db", tc.CDN{})
+ cols := test.ColsFromStructByTag("db", v13.CDN{})
rows := sqlmock.NewRows(cols)
for _, ts := range testCDNs {
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services