rob05c commented on issue #3296: Change TO cdns/dnsseckeys to abstract 
versioning
URL: https://github.com/apache/trafficcontrol/pull/3296#issuecomment-460417244
 
 
   So, I took a stab at making the versioning better, too:
   
   
https://github.com/rob05c/trafficcontrol/commit/4732c665f3d3b1d05bd13154576aa21670e2df77
   
   
https://github.com/rob05c/trafficcontrol/blob/4732c665f3d3b1d05bd13154576aa21670e2df77/lib/go-tc/deliveryservices.go
   
   
https://github.com/rob05c/trafficcontrol/blob/4732c665f3d3b1d05bd13154576aa21670e2df77/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
   
   
https://github.com/rob05c/trafficcontrol/blob/4732c665f3d3b1d05bd13154576aa21670e2df77/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv11.go
   
   So, this puts all the logic of the latest version in `deliveryservices.go`, 
and each version `deliveryservicesv11.go` etc is identical to the previous 
except `V11` -> `V13`.
   
   So, to add a new version, all you have to do is
   1. Add the new struct in `lib/go-tc`, e.g. `type DeliveryServiceNullableV15 
struct {DeliveryServiceNullableV13; ConsistentHashRegex *string}` with its 
conversion func, sanitize, and update `type DeliveryServiceNullable 
DeliveryServiceNullableV15`
   2. Add your logic to 
`traffic_ops_golang/deliveryservices/deliveryservices.go`
   3. `cp deliveryservicesv11.go deliveryservicesv15.go && sed -i 's/V11/V15/' 
deliveryservicesv15.go`
   
   We can and should add those steps to the documentation, and possibly scripts 
to make the new `deliveryservicesv1x.go` files.
   
   The generated code isn't ideal, but there's no logic there, and whenever Go2 
is out, we should be able to use Generics to get rid of it.
   
   (FYI I attempted to write Go ducktyping/interfaces to abstract the generic 
stuff, I think it's possible, but it'd be a mess.)
   
   But, you don't have to touch old versions, when adding a new version. That 
lets you add e.g. 1.5 without having to touch anything in 1.4, 1.3, 1.2, 1.1. 
Only the latest-version `deliveryservices.go`, and things for the version 
you're adding.
   
   What do you think of that solution?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to