Skip to content

Fix unmarshalling of OriginCACertificate#387

Merged
patryk merged 3 commits intocloudflare:masterfrom
player-two:fix-origin-ca-unmarshal
Dec 4, 2019
Merged

Fix unmarshalling of OriginCACertificate#387
patryk merged 3 commits intocloudflare:masterfrom
player-two:fix-origin-ca-unmarshal

Conversation

@player-two
Copy link
Copy Markdown

@player-two player-two commented Dec 1, 2019

Fixes #190

Description

The format of the expires_on field differs from what is documented, and the json parser makes CreateOriginCertificate() always return an error, even if the certificate was created. This change introduces custom timestamp parsing that works for both the actual and documented formats.

Has your change been tested?

I wrote a tiny test program that calls CreateOriginCertificate() and checked that the cert object is populated and the error is nil.

Screenshots (if appropriate):

N/A

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@player-two
Copy link
Copy Markdown
Author

The other way to fix this is introduce a new type for just the field and modify the struct definition to

type OriginCACertificate struct {
	ExpiresOn certificateExpiresOn `json:"expires_on,omitempty"`

That would remove the need to overload MarshalJSON() for the struct, but it would mean any code accessing the field would have to explicitly convert to time.Time. I opted to introduce a little more mess here to make usage easier.

@patryk
Copy link
Copy Markdown

patryk commented Dec 4, 2019

Thanks @player-two ! I have modified it slightly with help of the aliasing method described in http://choly.ca/post/go-json-marshalling/

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.

JSON Unmarshall error when using CreateOriginCertificate

3 participants