Created
February 12, 2018 16:55
-
-
Save 46bit/3802a765865d3700b8277170bde5c71e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package broker | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| ) | |
| type ProvisionParameters struct { | |
| RestoreFromLatestSnapshotOf *string `json:"restore_from_latest_snapshot_of"` | |
| } | |
| func ParseProvisionParameters(data []byte) (*ProvisionParameters, error) { | |
| var parsedParams provisionParametersParser | |
| err := json.Unmarshal(data, &parsedParams) | |
| if err != nil { | |
| return nil, err | |
| } | |
| if len(parsedParams.invalid) > 0 { | |
| return nil, fmt.Errorf("unknown provision parameters: %v", parsedParams.invalid) | |
| } | |
| return &parsedParams.valid, nil | |
| } | |
| type provisionParametersParser struct { | |
| valid ProvisionParameters | |
| invalid map[string]interface{} | |
| } | |
| func (p *provisionParametersParser) UnmarshalJSON(bs []byte) error { | |
| if err := json.Unmarshal(bs, &p.valid); err != nil { | |
| return err | |
| } | |
| if err = json.Unmarshal(bs, &p.invalid); err != nil { | |
| return err | |
| } | |
| delete(p.invalid, "restore_from_latest_snapshot_of") | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment