rob05c commented on a change in pull request #2364: Fix Traffic Ops Go to use 
transactions for deliveryservices, sslkeys, urisigning
URL: https://github.com/apache/trafficcontrol/pull/2364#discussion_r196446230
 
 

 ##########
 File path: lib/go-tc/deliveryservices.go
 ##########
 @@ -205,6 +216,213 @@ type DeliveryServiceNullableV13 struct {
        TRRequestHeaders         *string          
`json:"trRequestHeaders,omitempty"`
 }
 
+// NewDeliveryServiceNullableV13FromV12 creates a new V13 DS from a V12 DS, 
filling new fields with appropriate defaults.
+func NewDeliveryServiceNullableV13FromV12(ds DeliveryServiceNullableV12) 
DeliveryServiceNullableV13 {
+       newDS := DeliveryServiceNullableV13{DeliveryServiceNullableV12: ds}
+       newDS.Sanitize()
+       return newDS
+}
+
+func (ds *DeliveryServiceNullableV12) Sanitize() {
+       if ds.GeoLimitCountries != nil {
+               *ds.GeoLimitCountries = 
strings.ToUpper(strings.Replace(*ds.GeoLimitCountries, " ", "", -1))
+       }
+       if ds.ProfileID != nil && *ds.ProfileID == -1 {
+               ds.ProfileID = nil
+       }
+       if ds.EdgeHeaderRewrite != nil && 
strings.TrimSpace(*ds.EdgeHeaderRewrite) == "" {
+               ds.EdgeHeaderRewrite = nil
+       }
+       if ds.MidHeaderRewrite != nil && 
strings.TrimSpace(*ds.MidHeaderRewrite) == "" {
+               ds.MidHeaderRewrite = nil
+       }
+       if ds.RoutingName == nil || *ds.RoutingName == "" {
+               ds.RoutingName = util.StrPtr(DefaultRoutingName)
+       }
+}
+
+func getTypeName(tx *sql.Tx, id int) (string, bool, error) {
+       name := ""
+       if err := tx.QueryRow(`SELECT name from type where id=$1`, 
id).Scan(&name); err != nil {
+               if err == sql.ErrNoRows {
+                       return "", false, nil
+               }
+               return "", false, errors.New("querying type name: " + 
err.Error())
+       }
+       return name, true, nil
+}
+
+func requiredIfMatchesTypeName(patterns []string, typeName string) 
func(interface{}) error {
+       return func(value interface{}) error {
+               switch v := value.(type) {
+               case *int:
+                       if v != nil {
+                               return nil
+                       }
+               case *bool:
+                       if v != nil {
+                               return nil
+                       }
+               case *string:
+                       if v != nil {
+                               return nil
+                       }
+               case *float64:
+                       if v != nil {
+                               return nil
+                       }
+               default:
+                       return fmt.Errorf("validation failure: unknown type 
%T", value)
+               }
+               pattern := strings.Join(patterns, "|")
 
 Review comment:
   I didn't write, just moved

----------------------------------------------------------------
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