You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/07/04 02:39:36 UTC
[trafficcontrol] 11/15: define CRUDFactory function type to cleanup
signatures
This is an automated email from the ASF dual-hosted git repository.
dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 0ad2e84d8debbf127f9e3dca4b60fb41b39cd645
Author: Dylan Volz <Dy...@comcast.com>
AuthorDate: Wed Jun 27 14:50:41 2018 -0600
define CRUDFactory function type to cleanup signatures
---
traffic_ops/traffic_ops_golang/api/api.go | 2 ++
traffic_ops/traffic_ops_golang/api/shared_handlers.go | 8 ++++----
traffic_ops/traffic_ops_golang/asn/asns.go | 2 +-
traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go | 2 +-
traffic_ops/traffic_ops_golang/cdn/cdns.go | 2 +-
traffic_ops/traffic_ops_golang/coordinate/coordinates.go | 2 +-
.../traffic_ops_golang/deliveryservice/deliveryservicesv12.go | 2 +-
.../traffic_ops_golang/deliveryservice/deliveryservicesv13.go | 2 +-
.../deliveryservice/request/comment/comments.go | 2 +-
.../traffic_ops_golang/deliveryservice/request/requests.go | 6 +++---
traffic_ops/traffic_ops_golang/division/divisions.go | 2 +-
traffic_ops/traffic_ops_golang/origin/origins.go | 2 +-
traffic_ops/traffic_ops_golang/parameter/parameters.go | 2 +-
traffic_ops/traffic_ops_golang/physlocation/phys_locations.go | 2 +-
traffic_ops/traffic_ops_golang/profile/profiles.go | 2 +-
.../traffic_ops_golang/profileparameter/profile_parameters.go | 2 +-
traffic_ops/traffic_ops_golang/region/regions.go | 2 +-
traffic_ops/traffic_ops_golang/role/roles.go | 2 +-
traffic_ops/traffic_ops_golang/server/servers.go | 2 +-
traffic_ops/traffic_ops_golang/status/statuses.go | 2 +-
traffic_ops/traffic_ops_golang/tenant/tenancy.go | 2 +-
traffic_ops/traffic_ops_golang/types/types.go | 2 +-
22 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/api/api.go b/traffic_ops/traffic_ops_golang/api/api.go
index 99a4d89..ec3f9f9 100644
--- a/traffic_ops/traffic_ops_golang/api/api.go
+++ b/traffic_ops/traffic_ops_golang/api/api.go
@@ -44,6 +44,8 @@ const DBContextKey = "db"
const ConfigContextKey = "context"
const ReqIDContextKey = "reqid"
+type CRUDFactory func(reqInfo *APIInfo) CRUDer
+
// WriteResp takes any object, serializes it as JSON, and writes that to w. Any errors are logged and written to w via tc.GetHandleErrorsFunc.
// This is a helper for the common case; not using this in unusual cases is perfectly acceptable.
func WriteResp(w http.ResponseWriter, r *http.Request, v interface{}) {
diff --git a/traffic_ops/traffic_ops_golang/api/shared_handlers.go b/traffic_ops/traffic_ops_golang/api/shared_handlers.go
index 46f4b77..237cc60 100644
--- a/traffic_ops/traffic_ops_golang/api/shared_handlers.go
+++ b/traffic_ops/traffic_ops_golang/api/shared_handlers.go
@@ -120,7 +120,7 @@ func decodeAndValidateRequestBody(r *http.Request, v Validator) []error {
// combines the path and query parameters
// produces the proper status code based on the error code returned
// marshals the structs returned into the proper response json
-func ReadHandler(typeFactory func(reqInfo *APIInfo) CRUDer) http.HandlerFunc {
+func ReadHandler(typeFactory CRUDFactory) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
//create error function with ResponseWriter and Request
handleErrs := tc.GetHandleErrorsFunc(w, r)
@@ -216,7 +216,7 @@ func ReadOnlyHandler(typeFactory func(reqInfo *APIInfo) Reader) http.HandlerFunc
// *decoding and validating the struct
// *change log entry
// *forming and writing the body over the wire
-func UpdateHandler(typeFactory func(reqInfo *APIInfo) CRUDer) http.HandlerFunc {
+func UpdateHandler(typeFactory CRUDFactory) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
//create error function with ResponseWriter and Request
handleErrs := tc.GetHandleErrorsFunc(w, r)
@@ -332,7 +332,7 @@ func UpdateHandler(typeFactory func(reqInfo *APIInfo) CRUDer) http.HandlerFunc {
// *current user
// *change log entry
// *forming and writing the body over the wire
-func DeleteHandler(typeFactory func(reqInfo *APIInfo) CRUDer) http.HandlerFunc {
+func DeleteHandler(typeFactory CRUDFactory) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
@@ -422,7 +422,7 @@ func DeleteHandler(typeFactory func(reqInfo *APIInfo) CRUDer) http.HandlerFunc {
// *decoding and validating the struct
// *change log entry
// *forming and writing the body over the wire
-func CreateHandler(typeConstructor func(reqInfo *APIInfo) CRUDer) http.HandlerFunc {
+func CreateHandler(typeConstructor CRUDFactory) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/asn/asns.go b/traffic_ops/traffic_ops_golang/asn/asns.go
index 0886c6f..af59b18 100644
--- a/traffic_ops/traffic_ops_golang/asn/asns.go
+++ b/traffic_ops/traffic_ops_golang/asn/asns.go
@@ -46,7 +46,7 @@ type TOASNV11 struct {
tc.ASNNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOASNV11{reqInfo, tc.ASNNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
index 505352b..1e12577 100644
--- a/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
+++ b/traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go
@@ -42,7 +42,7 @@ type TOCacheGroup struct {
v13.CacheGroupNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOCacheGroup{reqInfo, v13.CacheGroupNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/cdn/cdns.go b/traffic_ops/traffic_ops_golang/cdn/cdns.go
index 3412a4c..39e5492 100644
--- a/traffic_ops/traffic_ops_golang/cdn/cdns.go
+++ b/traffic_ops/traffic_ops_golang/cdn/cdns.go
@@ -43,7 +43,7 @@ type TOCDN struct {
v13.CDNNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOCDN{reqInfo, v13.CDNNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/coordinate/coordinates.go b/traffic_ops/traffic_ops_golang/coordinate/coordinates.go
index eaabede..3b978ac 100644
--- a/traffic_ops/traffic_ops_golang/coordinate/coordinates.go
+++ b/traffic_ops/traffic_ops_golang/coordinate/coordinates.go
@@ -43,7 +43,7 @@ type TOCoordinate struct {
v13.CoordinateNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOCoordinate{reqInfo, v13.CoordinateNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv12.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv12.go
index 5c5d1d9..cd16e7e 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv12.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv12.go
@@ -41,7 +41,7 @@ type TODeliveryServiceV12 struct {
tc.DeliveryServiceNullableV12
}
-func GetTypeV12Factory() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeV12Factory() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TODeliveryServiceV12{reqInfo, tc.DeliveryServiceNullableV12{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go
index fbd996e..d6170da 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go
@@ -60,7 +60,7 @@ func (ds *TODeliveryServiceV13) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, ds.DeliveryServiceNullableV13)
}
-func GetTypeV13Factory() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeV13Factory() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TODeliveryServiceV13{reqInfo, tc.DeliveryServiceNullableV13{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/request/comment/comments.go b/traffic_ops/traffic_ops_golang/deliveryservice/request/comment/comments.go
index 5887b8f..3818266 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/request/comment/comments.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/comment/comments.go
@@ -41,7 +41,7 @@ type TODeliveryServiceRequestComment struct {
tc.DeliveryServiceRequestCommentNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TODeliveryServiceRequestComment{reqInfo, tc.DeliveryServiceRequestCommentNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
index e2bd836..45c0ff9 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
@@ -41,7 +41,7 @@ type TODeliveryServiceRequest struct {
tc.DeliveryServiceRequestNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TODeliveryServiceRequest{reqInfo, tc.DeliveryServiceRequestNullable{}}
return &toReturn
@@ -447,7 +447,7 @@ WHERE id=:id`
////////////////////////////////////////////////////////////////
// Assignment change
-func GetAssignmentTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetAssignmentTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := deliveryServiceRequestAssignment{TODeliveryServiceRequest{reqInfo, tc.DeliveryServiceRequestNullable{}}}
return &toReturn
@@ -537,7 +537,7 @@ type deliveryServiceRequestStatus struct {
TODeliveryServiceRequest
}
-func GetStatusTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetStatusTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := deliveryServiceRequestStatus{TODeliveryServiceRequest{reqInfo, tc.DeliveryServiceRequestNullable{}}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/division/divisions.go b/traffic_ops/traffic_ops_golang/division/divisions.go
index 0e0e7e7..52a8e4c 100644
--- a/traffic_ops/traffic_ops_golang/division/divisions.go
+++ b/traffic_ops/traffic_ops_golang/division/divisions.go
@@ -41,7 +41,7 @@ type TODivision struct {
tc.DivisionNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TODivision{reqInfo, tc.DivisionNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/origin/origins.go b/traffic_ops/traffic_ops_golang/origin/origins.go
index e760660..82eb3ea 100644
--- a/traffic_ops/traffic_ops_golang/origin/origins.go
+++ b/traffic_ops/traffic_ops_golang/origin/origins.go
@@ -46,7 +46,7 @@ type TOOrigin struct {
v13.Origin
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOOrigin{reqInfo, v13.Origin{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters.go b/traffic_ops/traffic_ops_golang/parameter/parameters.go
index c0363f9..e21011d 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters.go
@@ -54,7 +54,7 @@ type TOParameter struct {
tc.ParameterNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOParameter{reqInfo, tc.ParameterNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go b/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
index 8528341..b9de171 100644
--- a/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
+++ b/traffic_ops/traffic_ops_golang/physlocation/phys_locations.go
@@ -41,7 +41,7 @@ type TOPhysLocation struct {
tc.PhysLocationNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOPhysLocation{reqInfo, tc.PhysLocationNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/profile/profiles.go b/traffic_ops/traffic_ops_golang/profile/profiles.go
index 87c99a0..b3cbaa2 100644
--- a/traffic_ops/traffic_ops_golang/profile/profiles.go
+++ b/traffic_ops/traffic_ops_golang/profile/profiles.go
@@ -52,7 +52,7 @@ type TOProfile struct {
v13.ProfileNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOProfile{reqInfo, v13.ProfileNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
index e6e3366..9d3c7b7 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
@@ -47,7 +47,7 @@ type TOProfileParameter struct {
v13.ProfileParameterNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOProfileParameter{reqInfo, v13.ProfileParameterNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/region/regions.go b/traffic_ops/traffic_ops_golang/region/regions.go
index f963923..a8d074b 100644
--- a/traffic_ops/traffic_ops_golang/region/regions.go
+++ b/traffic_ops/traffic_ops_golang/region/regions.go
@@ -37,7 +37,7 @@ type TORegion struct {
tc.Region
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TORegion{reqInfo, tc.Region{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/role/roles.go b/traffic_ops/traffic_ops_golang/role/roles.go
index 763ab62..ba5916f 100644
--- a/traffic_ops/traffic_ops_golang/role/roles.go
+++ b/traffic_ops/traffic_ops_golang/role/roles.go
@@ -42,7 +42,7 @@ type TORole struct {
v13.Role
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TORole{reqInfo, v13.Role{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go
index 7e51ab3..879d165 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -44,7 +44,7 @@ type TOServer struct {
v13.ServerNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOServer{reqInfo, v13.ServerNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/status/statuses.go b/traffic_ops/traffic_ops_golang/status/statuses.go
index 5821a35..9c405af 100644
--- a/traffic_ops/traffic_ops_golang/status/statuses.go
+++ b/traffic_ops/traffic_ops_golang/status/statuses.go
@@ -41,7 +41,7 @@ type TOStatus struct {
tc.StatusNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOStatus{reqInfo, tc.StatusNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/tenant/tenancy.go b/traffic_ops/traffic_ops_golang/tenant/tenancy.go
index 6b66141..202dd70 100644
--- a/traffic_ops/traffic_ops_golang/tenant/tenancy.go
+++ b/traffic_ops/traffic_ops_golang/tenant/tenancy.go
@@ -298,7 +298,7 @@ type TOTenant struct {
tc.TenantNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOTenant{reqInfo, tc.TenantNullable{}}
return &toReturn
diff --git a/traffic_ops/traffic_ops_golang/types/types.go b/traffic_ops/traffic_ops_golang/types/types.go
index ab95214..a8c809f 100644
--- a/traffic_ops/traffic_ops_golang/types/types.go
+++ b/traffic_ops/traffic_ops_golang/types/types.go
@@ -41,7 +41,7 @@ type TOType struct {
tc.TypeNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+func GetTypeSingleton() api.CRUDFactory {
return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOType{reqInfo, tc.TypeNullable{}}
return &toReturn