Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeepCachingType -- "NEVER" is now default #1844

Merged
merged 3 commits into from
Feb 12, 2018
Merged

DeepCachingType -- "NEVER" is now default #1844

merged 3 commits into from
Feb 12, 2018

Conversation

dangogh
Copy link
Member

@dangogh dangogh commented Feb 2, 2018

When creating a new deliveryservice, the new DeepCachingType entry should have a reasonable default that's not invalid.

@rawlinp this is what I was suggesting...

@dangogh dangogh added this to the 2.2.0 milestone Feb 2, 2018
@@ -191,7 +191,7 @@ type DeepCachingType string
const (
DeepCachingTypeAlways = DeepCachingType("ALWAYS")
DeepCachingTypeNever = DeepCachingType("NEVER")
DeepCachingTypeInvalid = DeepCachingType("")
DeepCachingTypeInvalid = DeepCachingType("INVALID")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of the enum should match the default value of the type, i.e. "". So per

case "":
+		// default when omitted
+		return DeepCachingTypeNever

below, DeepCachingTypeNever = DeepCachingType("NEVER") should be
DeepCachingTypeNever = DeepCachingType("")

This will prevent errors if someone default-initializes a DeepCachingType, e.g. t := DeepCachingType{} or t := DeepCachingType("") expecting it to be the default for the enum.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point.. I'll change that..

@asfgit
Copy link
Contributor

asfgit commented Feb 2, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/976/
Test PASSed.

@rob05c
Copy link
Member

rob05c commented Feb 2, 2018

Is this ever serialised to JSON, e.g. for the Client/Server? Might need
func (t DeepCachingType) MarshalJSON() ([]byte, error) { return json.Marshal(t.String()) } too.

That will make everything but string(t) work (which should never be done). There's no perfect solution, but this is probably the safest, and the only way to make DeliveryService{} default to Never.

@asfgit
Copy link
Contributor

asfgit commented Feb 2, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/977/
Test PASSed.

@dangogh
Copy link
Member Author

dangogh commented Feb 2, 2018

adding tests to verify JSON conversions

@dangogh
Copy link
Member Author

dangogh commented Feb 2, 2018

@rob05c helpful suggestions.. thanks.. anything more?

@dangogh
Copy link
Member Author

dangogh commented Feb 2, 2018

fyi -- would love to see this get into 2.2 so no one starts relying on current behavior

@rob05c
Copy link
Member

rob05c commented Feb 2, 2018

Looks good! Sorry about the delay, I didn't think about JSON at first.

Again, there is no perfect solution, but IMO this is the best option, it gives us a correct default that serializes and stringifies correctly, and works if someone default-constructs either the enum or things containing it, DeepCachingType{} or DeliveryService{}.

A type DeepCachingType struct{s string}; const DeepCachingTypeAlways = DeepCachingType{s: "ALWAYS"} would be a perfect solution that prevented wrong string(t) calls, but Go doesn't allow const structs :(

As the RM, I'll make sure this gets in 2.2.

Copy link
Member

@rob05c rob05c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested running TO yet, but the code looks good.

@asfgit
Copy link
Contributor

asfgit commented Feb 2, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/incubator-trafficcontrol-PR/979/
Test PASSed.

@rawlinp
Copy link
Contributor

rawlinp commented Feb 2, 2018

looks good to me 👍

@dewrich
Copy link
Contributor

dewrich commented Feb 8, 2018

@rob05c Gonna leave this one up to you to merge for 2.2

@rob05c rob05c merged commit 64f26d5 into apache:master Feb 12, 2018
@dangogh dangogh deleted the go-deepcaching-default branch March 2, 2018 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants