rob05c commented on a change in pull request #3989: Rewrote
/deliveryservices/request to Go
URL: https://github.com/apache/trafficcontrol/pull/3989#discussion_r335203566
##########
File path: lib/go-tc/enum.go
##########
@@ -220,6 +220,75 @@ func CacheStatusFromString(s string) CacheStatus {
}
}
+// Protocol represents an ATC-supported content delivery protocol.
+type Protocol string
Review comment:
FWIW I'm a fan of stronger typing. I like to do this for a couple reasons
- Maps are probably the biggest. It lets you do e.g.
`map[tc.DeliveryServiceName]tc.Protocol` and makes the code self-documenting,
instead of `map[string]int // map[deliveryservice]protocol`
- It makes a certain type of error impossible, e.g. passing a port instead
of a protocol, or a cachegroup name instead of a ds name. I know it sounds like
"who would do that," but I've certainly don't it in the past, especially with
the confusing code and terribly-named variables in the old Perl cache config
gen.
- In Go, it lets you define functions on it, like the Unmarshal here, which
can make the code a little easier to read
There are disadvantages of course, the biggest that comes to mind is the
readability when you have to `proto.String()` at the edge. But IMO the
advantages are usually greater. My 2ยข
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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